Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Monit丢失bash变量?_Bash_Monit - Fatal编程技术网

Monit丢失bash变量?

Monit丢失bash变量?,bash,monit,Bash,Monit,试图让monit监视我们编写的自定义守护进程,但它不能与bash停止/启动脚本一起工作。如果我从命令行手动运行停止/启动脚本,每次都会100%完美地运行。如果通过monit执行get,则变量为空。从我遇到问题的脚本中摘录: GETPID=$(ps aux | grep unicorn | grep master | cut -d" " -f7) echo "getPID : $GETPID" echo $G

试图让monit监视我们编写的自定义守护进程,但它不能与bash停止/启动脚本一起工作。如果我从命令行手动运行停止/启动脚本,每次都会100%完美地运行。如果通过monit执行get,则变量为空。从我遇到问题的脚本中摘录:

GETPID=$(ps aux | grep unicorn | grep master | cut -d" " -f7)
echo "getPID : $GETPID"                                             
echo $GETPID > $PIDFILE
使用monit执行时,
$GETPID
变量为空。用手工操作,效果很好


有人有什么想法吗?

一般来说,解析
ps
ls
的输出不是一个好主意

您可以使用
proc
文件系统上的
find
编写一个简单的
pgrep

# find /proc/ -maxdepth 2 -type l -name exe -lname '/bin/bash' -printf '%h\n' 2>/dev/null | sed 's/.*\///'
3580
3595
9504
9869
10054
10156
10193
# pgrep bash
3580
3595
9504
9869
10054
10156
10193

谢谢你的帮助。问题是rvm安装中的unicorn路径。

如果添加shebang行
#是否有帮助/bin/sh
作为文件的第一行?得到了一个#/bin/bash作为第一行,上面的代码实际上只是脚本的一个摘录。出于好奇:为什么不使用
pgrep
pidof
来获取您的PID?尝试从脚本中回显
$PATH
。手动运行,然后在monit内运行。如果在monit中运行时
$PATH
为空,则必须在脚本中提供
ps
的完整路径。有关启动非交互式脚本的更多信息,请参阅。在脚本顶部,将stderr重定向到文件(
exec 2>/tmp/log
),然后调用
set-x
;然后在脚本运行后检查日志文件。在问题中编辑任何特别有趣的内容——这将显示建议的问题所询问的空路径情况(通过让ps等命令向stderr发出not found errors)。