简体   繁体   English

如何在启动时运行 nohup,同时将 nohup.out 写入选定目录

[英]How to run nohup on boot while writing nohup.out to a selected directory

Im going to have to run a nohup command that will run for months and generate tons of logs, so I want to write the nohup.out file to a directory that contains the rest of the code.我将不得不运行一个将运行数月并生成大量日志的 nohup 命令,因此我想将 nohup.out 文件写入包含其余代码的目录。 My simple script to execute on every startup is:我在每次启动时执行的简单脚本是:

sudo su ubuntu
cd /home/ubuntu/folder
nohup /home/ubuntu/folder/start_server.sh&

If I do a crontab job that runs the script, all of the nohup logs still go into /var/log/syslog .如果我执行运行脚本的 crontab 作业,所有 nohup 日志仍会进入/var/log/syslog

If I do the same with cloud-init since im working on ec2, all logs into /var/log/cloud-init-output.log .如果我在使用 ec2 后对 cloud-init 执行相同操作,则所有日志都将记录到/var/log/cloud-init-output.log

How can I make nohup run in a choosen directory ( /home/ubuntu/folder in my case) only?如何让 nohup 仅在选择的目录(在我的情况下为/home/ubuntu/folder )中运行?

解决方案是运行 crontab,我的启动脚本运行nohup /home/ubuntu/folder/start_server.sh > nohup.out而不是nohup /home/ubuntu/folder/start_server.sh&

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM