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

后端 未结 7 1494
星月不相逢
星月不相逢 2020-12-30 21:35

I have a daemon I have written using Python. When it is running, it has a PID file located at /tmp/filename.pid. If the daemon isn\'t running then PID file doesn\'t exist.

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 21:53

    If it is bash scripting you are wondering about, something like this would work:

    if [ ! -f "$FILENAME" ]; then
       python daemon.py restart
    fi
    

    A better option may be to look into lockfile

提交回复
热议问题