I want to get the output of tail -f /var/log/apache2/error.log | grep “trace1” into a file. But tail -f /var/log/apache2/error.log | grep “trace1” > output.txt does not work, while the first command gives an output in my terminal window as expected. I guess it has to do with the fol…
Tag: redirect
Is pipe in linux asynchronous or not?
I thought that when i running below commands Linux process will be when sleep 10 is end -> sleep 2 (when sleep 2 is end)-> sleep 5 that’s i thought But in Linux bash sleep 10, sleep 2, sleep 5 are in ps same time Standard output of sleep 10 process will be redirected to sleep 5’s process But…
Shell script: Redirect output of program to changing files
My goal: I would like to redirect the stdout output of my program foo to a changing output file depending on the running time of the program. The program foo itself is listening on a bsd socket for arriving packets and displays information contained in them. So essentially, after running the program foo for 1…
Does an argument after a redirection do anything?
Is any argument after a redirection ignored, or does it have any unintended consequences? I was surprised to find that a typo I made in my bash script made absolutely no difference because it was specified after a redirect. E.g. I expected it to complain about something like this But it doesn’t throw an…
no such file or directory after redirection – simple command line program
Im programming a shell. This is a small piece of it that handles redirects. I only included the snippet that is causing the error. This portion of the program is supposed to take a command/argument line and execute the line accordingly. The wc < junk > junk2 is an example of a command line input and for…
Spawn process and redirect current bash script’s output to it
How can I spawn a new background process from a bash script and redirect the current script’s stdout/stderr to that process’s stdin using fd redirection? I know of a few ways to accomplish the same effect, such as using a named pipe or a temporary file, using coprocs, or running the whole script i…
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 force HTTP to HTTPS with an exception?
So I had to force all connections via HTTP to go to HTTPS on a specific folder (e.g. “public_html/folder1”). I found a tutorial somewhere and used the following in an .htaccess file: Problem is, I have a folder inside that folder1 which should be allowed to be accessed via HTTP and not just HTTPS,…
system call open() creating executable
So my code creates and writes to the out_file properly. However, the file is an executable for some reason. I think the fault is in my open() call but I can’t seem to find why. Answer man 2 open explains why: So if you want a file that’s not executable, you can use: 0666 will suggest read/write fo…
sed – Piping a string before the last line in a file
I have a command that prints a single line. I want to add/pipe this line to a file, just above its last line. I just find an empty line in the correct place, above the last line. I notice that when I add any string as ‘$i foo’, the “foo” gets printed in the correct place, but I want th…