Bash chek如果在子进程中发生错误(命令&)

时间:2022-02-07 11:23:11

I running mongodb instance from bash scripts and I need to show user-friendly message if mogngo will crash during startup for some reason.

我从bash脚本运行mongodb实例,如果出于某种原因mogngo在启动期间崩溃,我需要显示用户友好的消息。

so I have that sort of code

所以我有那种代码

eval 'mongod --dbpath=$ABS_MONGO_DATA_PATH &' || printf "something bad happened"

but with that sort of notation error handler never called. But if I remove & sing, then after mongo initialization further script do not running because of mongod process waiting for a signals

但是那种符号错误处理程序永远不会被调用。但是如果我删除&唱歌,那么在mongo初始化之后,由于mongod进程等待信号,因此不会运行脚本

How could I resolve that issue?

我怎么能解决这个问题?

1 个解决方案

#1


1  

You don't need eval for this:

你不需要eval:

{ mongod --dbpath="$ABS_MONGO_DATA_PATH" ||
   printf "something bad happened"; } &

Instead of just running mongod in the background, run the entire command list in the background.

而不是只在后台运行mongod,在后台运行整个命令列表。

#1


1  

You don't need eval for this:

你不需要eval:

{ mongod --dbpath="$ABS_MONGO_DATA_PATH" ||
   printf "something bad happened"; } &

Instead of just running mongod in the background, run the entire command list in the background.

而不是只在后台运行mongod,在后台运行整个命令列表。