How can I check a file exists and execute a command if not?

[ -f /tmp/filename.pid ] || python daemon.py restart

-f checks if the given path exists and is a regular file (just -e checks if the path exists)

the [] perform the test and returns 0 on success, 1 otherwise

the || is a C-like or, so if the command on the left fails, execute the command on the right.

So the final statement says, if /tmp/filename.pid does NOT exist then start the daemon.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)