shell bash scripts : check process existed or not, if not existed then restart it

Put below scripts in your ~/.bash_profile or ~/.bashrc
It will auto run "unison" process if not running yet
when you open a new bash shell every time.
Change the process name "unison" for your case. :)

auto_unison() {
    u=`ps aux | grep unison | grep -v grep | wc -l`
    if [ $u -eq 0 ]
        unison > /dev/null 2>&1 &

Subscribe to Post, Code and Quiet Time.

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.