We have a script that is used to sync some directories to a USB disk drive. It is set to run once a day but often takes longer than that.
To ensure that multiple copies of the script don't run at the same time, we check the list of processes and if our script is present, we immediately exit.
#!/bin/bash #check if we are already running running=$(ps aux | /usr/bin/grep -i "usb_sync" | /usr/bin/grep -v grep | /usr/bin/grep -c bash) echo "usb_sync $running" >/opt/local/backup/usb_sync_log #If we are, the quit if [ $running -gt 1 ] ; then exit 0 fi
The problem is that this check works fine when running it via sudo and manual invocation through the CLI. However when it is run through cron, it will start regardless. I have tried a couple of different variations but they all seem to run.
This is on FreeNAS 11.2.