Sequentially run commands in bash script

安稳与你 提交于 2019-12-08 12:04:00

问题


I need to run two commands sequentially in daemon mode (the commands will output the errors on stderr). The problem is that even I dump all the output in /dev/null, the second command (run_cmd2) cannot be invoked. Here is my script

#! /bin/bash
nohup ./run_cmd1 &> /dev/null &
nohup ./run_cmd2 &> /dev/null &

Any ideas? Thank you in advance.


回答1:


How about using a file to communicate state?

run_cmd2 will wait until a file exists before running

when run_cmd1 is done, it will create the said file.

at the end of its run the run_cmd2 will delete the file, so run_cmd1 can run again

Or maybe they talk to each other using a port?

Or maybe a semaphore?

For more details: http://www.tldp.org/LDP/tlk/ipc/ipc.html



来源:https://stackoverflow.com/questions/23702536/sequentially-run-commands-in-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!