将脚本后台运行,并转存后台运行日志
nohup cmd 1 > info.log 2>&1 &
这是我自己用的测试脚本
#!/bin/bash
while(true)
do
currTime=$(date +"%Y-%m-%d %T")
echo $currTime
sleep 1
done
nohup ./yunxing.sh 1 > info.log 2>&1 &
可以看到后台echo输出已经保存到 info 文件中