Crontab running before nfs mounted

Solution 1:

You can use the mountpoint command to ensure the mount has taken place before you execute your command e.g. (assuming /abs is the mount point)

#!/bin/bash
while true
do
    if mountpoint -q /abs
        then
            /usr/bin/python /abs/path/to/script.py
            break
        fi
    sleep 10
done

Solution 2:

I'm not sure what the problem is since cron starts after networking. (At least in Red Hat and derivatives.) Are your mounts in /etc/fstab with _netdev option or else where?

The standard way to execute something on start up is to include it in /etc/rc.local. This will be ran after the network is initialized and all other services are started. (Including mounting of remote file systems.)

(Or is there a reason to only execute the script after a literal reboot?)

Solution 3:

Here are some ideas for you:

  1. check if NFS is mounted. If not, mount it, then run your script:

    [ ! -f /abs/path/to/script.py ] && mount -t nfs device dir && python /abs/path/to/script.py

  2. run your script in the start() function of the NFS init script:

    echo -n $"Starting NFS mountd: "
    daemon rpc.mountd $RPCMOUNTDOPTS
    RETVAL=$?
    echo
    [ $RETVAL -ne 0 ] && exit $RETVAL || python /abs/path/to/script.py
    

Solution 4:

To be absolutely sure that the python script is able to run. You would need to wrap it in a script stored on local storage to verify that the mount point has come up.

Something like (warning pseudo code):

while (!ScriptExists && ErrorCount < 10)
do
    mount /my/mount/point
    sleep 10
    ErrorCount++
done