在CentOS中,使用nohup
命令可以在后台运行Shell脚本,即使关闭终端或断开SSH连接,脚本也会继续运行
打开终端。
使用cd
命令导航到包含Shell脚本的目录。例如,如果脚本位于/home/user/scripts
目录中,请输入:
cd /home/user/scripts
nohup
命令运行Shell脚本。例如,如果脚本名为my_script.sh
,请输入:nohup ./my_script.sh &
这里,&
符号将脚本放入后台运行。
nohup
命令会将脚本的输出重定向到一个名为nohup.out
的文件中。如果你想将输出重定向到其他文件,请使用以下命令:nohup ./my_script.sh > output.log &
这将把输出保存到output.log
文件中。
现在,你可以关闭终端或断开SSH连接。脚本将继续在后台运行。
如果你想检查脚本的输出,可以使用tail
命令查看nohup.out
或output.log
文件的内容。例如:
tail -f nohup.out
或者
tail -f output.log
这样,你就可以在CentOS中使用nohup
命令运行Shell脚本了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>