1

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

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 

# 

我该如何真正解决这种行为?

4

1 回答 1

1
top -n 1 -b

在循环中跟踪并附加到文件中。
将循环包装在脚本中并使用 & 从终端启动它。

于 2017-07-10T20:36:02.340 回答