如何在后台进行顶级运行?它需要运行并记录输出.不死不死,不僵尸



我正在尝试制作一个脚本,将顶部输出记录到嵌入式系统的后台文件中。但是一旦我把它放在后台,它要么退出,要么僵尸起来。在后台运行东西的系统问题是什么? 我的脚本

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

我正在尝试执行它

# nohup sh top_log.sh &

[4] 3051559
appending output to nohup.out
# 

[4] + Stopped (tty output) nohup sh top_log.sh

和作为

[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 
# 

我如何实际解决这种行为?

top -n 1 -b

在循环中尾部并附加到文件中。
将循环包装在脚本中,并使用 &.

最新更新