您的位置:首页 > 运维架构 > Linux

linux nohup

2016-07-07 21:18 573 查看
If standard output is a terminal, append output to 'nohup.out'
If standard error is a terminal, redirect it to standard output. To save output to FILE, use 'nohup COMMAND > FILE'.

nohup: ignoring input and appending output to `nohup.out'

nohup sh test.sh &

会将脚本中的输出(标准输出和错误输出)都append到本路径下的nohup.out文件中

如果使用nohup命令提交作业,那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件:

nohup command > myout.file 2>&1 &

应用:
1 我不需要将脚本中的错误输出写到nohup文件中
nohup sh test.sh 2>/dev/null &

2 我需要将脚本中的输出输出到一个文件中而不是nohup.out中

疑问如果我退出了终端,我在ps -ef |grep "test.sh"的时候,并不会显示是重定向到哪个文件,这个时候如何找出呢?

方法
第一步:
ps -ef |grep "test.sh" 找出这个进程的pid

[root@master scripts]# ps -ef |grep "test.sh"
root 2700 1 0 20:38 ? 00:00:00 sh test.sh

第二步: 利用lsof列出这个进程所占用的文件
lsof -p 2700

注意: nohup python test.py & 可能tail -f nohup.out 得到的结果不是你想要得,这个就要理解python中的(print 函数 sys.stdout.write() sys.stdout.flush()) 得深入理解一下了。有个缓冲的概念。

本文出自 “崔德华运维打工从业路” 博客,请务必保留此出处http://cuidehua.blog.51cto.com/5449828/1812430
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: