Simulate cron environment

Sometimes scripts aren’t working in cron, but they’re working manually. To debug them it’s helpful to simulate their running under cron environment.

add this to cron and let it to run at least once

* * * * * env > ~/cron_env

run this command to simulate environment:

env - `cat ~/cron_env` /bin/sh

Don’t run script if it’s running

The script will start only in case if the same script is not running.

#!/bin/bash
if ps -ef | grep -v grep | grep "process name" ; then
    echo "process running"
    exit 0
else
    echo "process not running"
    exit 0
fi