In order to remotely start a program, log its output and immediately see that log, I'm using this script:

为了远程启动程序,记录其输出并立即看到该日志,我正在使用此脚本:

nohup mycommand 2>&1 | tee -a server.log &

Now, I would like to store in a file the pid of the newly started mycommand (whose name is very generic, I can't just use pgrep as there would be a risk of collision).

现在,我想在一个文件中存储新启动的mycommand的pid(其名称非常通用,我不能只使用pgrep,因为存在冲突的风险)。

If I just add echo $! > mycommand.pid I get the pid of tee.

如果我只是添加echo $! > mycommand.pid我得到了发球的pid。

How can I reliably write the pid of mycommand to a file ?

如何可靠地将mycommand的pid写入文件?

And by the way, why doesn't this give the right pid ?

顺便说一句,为什么这不给出正确的pid?

( nohup mycommand 2>&1 ; echo $! > mycommand.pid ) | tee -a server.log &

1 个解决方案

#1


1

OK, this simple variant works :

好的,这个简单的变体有效:

( nohup mycommand 2>&1 & echo $! > mycommand.pid ) | tee -a server.log &

I'm not sure why the ; didn't work and why I have to use & instead.

我不确定为什么;不起作用,为什么我必须使用&而不是。

更多相关文章

  1. Linux文件归档和解压缩
  2. 如何使用“tail -1 * / filename”拖尾多个文件的最后一行
  3. Linux文件权限概念
  4. 将JSON文件中的所有时间戳转换为bash(Ubuntu)中的unix时间戳
  5. 小记——inotify文件监控
  6. Linux下运行.cpp文件
  7. linux下如何导出.txt文件?
  8. Linux的五个文件查找命令:find,locate,whereis,which,type
  9. Re:从零开始的Linux之路(文件权限)

随机推荐

  1. 在asp.net中使用JQuery Ajax相关用法总结
  2. 分析.NET的异常处理
  3. 介绍ASP.NET中的MVC如何从控制器传递数据
  4. 如何使用asp.net实现文件和文件夹的复制
  5. 详解ASP.NET中连接数据库配置方法
  6. asp.net利用ashx实现验证码功能详解
  7. 在ASP.NET中实现DES加密与解密MD5加密功
  8. 在Asp.net的MVC中利用swupload实现多图片
  9. 支付宝的支付接口在.net中的使用
  10. C#中关于AutoMapper应用的实例