I’m using Amazon Linux. I want to start a process provided one isn’t running already. This is a bash script I embed within a Jenkins Maven job. So I have
pids=$(pidof /usr/bin/Xvfb)
if [ ! -n "$pids" ]; then
Xvfb :0 -screen 5 1024x768x8 &
fi
Unfortunately, if there is no process, the line “pids=$(pidof /usr/bin/Xvfb)” returns a failing exit code and none of the other lines following are executed. Is there a way I can write the above such that no failed exit codes will be returned?
if ! pidof /usr/bin/Xvfb; then : do something; fi
if ! pidof /usr/bin/Xvfb; then Xvfb :0 -screen 5 1024x768x8 & fi"
if you want to run command in background.if ! pgrep Xvfb; then ...
should do the trick.