this is my script: here is errormessage My linux version is centos 7.0,and when i use loop only in script not in function,there will not be erros when process Answer There are a number of sources of confusion here. First, whenever you use anything like echo somethingorother in backquotes, you’re doing s…
Tag: bash
Redirecting output of a program to a rotating file
I am trying to redirect the output of a continuously running program to a file say error_log. The command I am using looks like this, where myprogram.sh runs continuously generating data and writing to /var/log/httpd/error_log myprogram.sh >> /var/log/httpd/error_log Now I am using logrotate to rotate t…
How to append a line at the end of /etc/sudoers file using shell script (without using pssh tool)
I want to append a few lines at the end of /etc/sudoers file. Below is an example of lines I want to append. Can anyone suggest how to append this using a shell script? Answer
How to use content of variable in bash to pass to find in script?
In a bash script I’m trying to use the content of a variable to be used as options for the find command: The aim is to set proper access rights as for what ever reason quite some files (such as pictures or office documents) are marked executable. So in reality the script above has several arrays with fi…
How to get stdout/stderr in logfiles immediately?
To run some Python program I use the following bash script: However I can get information after the prog is terminated only. When program is running there are not any data in these files. Can I override this behavior to get log data immediately? My OS is Raspbian. Answer I suspect the program needs to flush s…
Bash/SH, Same command different output?
And the last one is correct. Why is that? and how to solve it? Answer Per POSIX, echo supports no options. Therefore, when echo -n is run with sh, it outputs literal -n instead of interpreting -n as the no-trailing-newline option: Note: Not all sh implementations behave this way; some, such as on Ubuntu (wher…
How can low frame rate video be made to look more smooth?
I am trying to clean up a video that was recorded in 2003 in low-light conditions on what was possibly a cameraphone. The video has been cleaned up somewhat (cropped, logos removed and stabilized), but it remains quite jerky, due in large part to its low frame rate. What are some tricks that might clean up th…
BASH / sed – not giving same output for simple sed commands
Box 1: uname -srm Box 2: uname -srm; cat /etc/debian_version BASH on box1 is: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16) BASH on box2 is: GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) On both boxes, I’m have the following script: All commands are same. This is what I’m…
Read line by line and print matches line by line
I am new to shell scripting, it would be great if I can get some help with the question below. I want to read a text file line by line, and print all matched patterns in that line to a line in a new text file. For example: The intended output is as follows: I tried the following code: which
Executing Bash commands using C code
I’m trying to use file.cpp to execute some simple bash commands. Code works for commands like ls, gedit, echo but fails at cd command. Here is my file.cpp: I execute it after compiling using ./file and my terminal output is, Current directory didn’t change to /etc. I have tried changing cd /etc to…