Linux命令(76)之nohup

linux命令之nohup

1.nohup介绍

linux命令nohup(简称:no hang up)是用于在系统后台不挂断地运行要执行的命令,其默认输出在$HOME/nohup.out

2.nohup用法

nohup command [arg...] [&]

command:要执行的命令

arg:参数,例如:可以指定输出文件

&:让命令在服务器后台执行,即使终端退出后,命令仍旧执行

3.实例

3.1.在服务器后台执行urandom.sh

urandom.sh

[root@rhel77 ~]# cat urandom.sh 
#!/bin/bash
while true;
do
tr -dc '_a-zA-Z0-9' </dev/urandom | head -c 5
echo
sleep 4
done

命令:

nohup sh /root/urandom.sh &

[root@rhel77 ~]# nohup sh /root/urandom.sh &
[1] 4566
[root@rhel77 ~]# nohup: ignoring input and appending output to ‘nohup.out’

[root@rhel77 ~]# ps -ef | grep urandom
root       4566   1930  0 09:05 pts/0    00:00:00 sh /root/urandom.sh
[root@rhel77 ~]# cat nohup.out 
xbF1Q
fimsX
xIdDt
WOl4Z
R73Ur
Im_GN
PlmFu
i_x_A
0ax2F
T5M6R
pA3ug
bW2Zq
WXUtM
5D8QM
EruPW
XfJCQ
5dY_n
ITZQQ
uSzQM
rWKm3
SQc6C
P6_qC
SpstK
5eSPp
ZW_MI
8R7Fy
xJ2o4
Ji2Q0
3o3c8
9T_0u
dWo2k
[root@rhel77 ~]# 

3.2.nohup执行urandom.sh,并自定义重定向

命令:

nohup sh /root/urandom.sh > urandom.log 2>&1 &
 

[root@rhel77 ~]# ps -ef |grep urandom
root       4566   1930  0 09:05 pts/0    00:00:00 sh /root/urandom.sh
root       4796   1930  0 09:08 pts/0    00:00:00 grep --color=auto urandom
[root@rhel77 ~]# kill -9 4566
[root@rhel77 ~]# nohup sh /root/urandom.sh > urandom.log 2>&1 &
[2] 4817
[1]   Killed                  nohup sh /root/urandom.sh
[root@rhel77 ~]# ps -ef |grep urandom
root       4817   1930  0 09:09 pts/0    00:00:00 sh /root/urandom.sh
root       4828   1930  0 09:09 pts/0    00:00:00 grep --color=auto urandom
[root@rhel77 ~]# cat urandom.log 
nohup: ignoring input
YDOUG
SuZFy
ERSK2
QRplg
kakyY
[root@rhel77 ~]# 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值