Forum OpenACS Q&A: crontab postgresql database restore not working - shell script


I'm having a very strange problem and I'm not sure where else to ask.

I've got a dotLRN installation that I've had for a the past 5 years running perfectly on Red Hat ES4. Each night we execute an automatic backup and restore onto a different server so that we have a failover environment ready for disaster recovery. These scripts are executed via crontab under the root, the dotlrn and the postgres user.

I've recently installed Red Hat 5 and have tried to get the same automatic script working. If I execute the shell script via the terminal, logged in as postgres user, it works fine. If I set up a crontab to run the same script it does not drop the database, or create the new one but will still execute the cat command to restore the database, so I get two sets of tables etc.

Script is as follows:
echo "-logged in as user - postgres" >>$logfile
echo "-drop the Database" >>$logfile
dropdb dotlrndb >>$logfile
echo "-wait for 30 seconds for the db to be dropped" >>$logfile
sleep 30
echo "-create a new Database" >>$logfile
createdb -E UNICODE dotlrndb >>$logfile
sleep 10
echo "-wait 10 seconds for the DB to create" >>$logfile
echo "-restoring database from backup">>$logfile
cat /data/restore/dotlrn_pgsql.dmp* | psql dotlrndb >>$logfile
echo "-database restore completed" >> $logfile

I found the solution elsewhere. The problem is that the environment variables for Postgresql need to be declared in the script file when run from Crontab but not when run from the terminal.

export PATH=$PATH:/usr/local/bin/:/usr/bin