Sudo times out during long running script

Solution 1:

If the script itself is run as sudo, it will not time out until the script has finished running. To ensure that sudo is used to run the script, I inserted the following lines near the top of my script:

if [ `whoami` != 'root' ];
then
    echo "This program needs to be run using 'sudo'"
    exit
fi

This ensures that the script has been started with sudo, and does not make any attempt to store passwords...