I am trying to make a script to log the top output to a file in the background for my embedded system. But as soon as I put it in background, it either exits or zombies up. What is the systems problem with running things in background ? My script
TOP_LOG_FILE=top_log.txt if [ -e $TOP_LOG_FILE ] ; then rm $TOP_LOG_FILE fi while true do echo "##"`date`"##" >> $TOP_LOG_FILE nohup top -n 1 >> $TOP_LOG_FILE sleep 1 echo "##xxxxxxxxxxx##" >> $TOP_LOG_FILE done
I am trying to execute it as
# nohup sh top_log.sh & [4] 3051559 appending output to nohup.out # [4] + Stopped (tty output) nohup sh top_log.sh
and as
[5] 3121193 sh: top_log.sh: cannot execute - No such file or directory [6] 3121194 # [6] Done > /dev/null [5] Done (126) top_log.sh #
How do I actually get around this behavior?
Advertisement
Answer
top -n 1 -b
Tail that in a loop and append to file.
Wrap your loop in a script and launch it from terminal with &.