Skip to content

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 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…

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…