expect script not running in cron "Urgent"

I wrote a script to download the files from sftp location to local. while running the script manually its working fine. when i schedule the same in cron its not working.... :wall::wall:

here is the script:

#!/bin/bash

PATH=/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/lib/jvm/jre-1.6.0-openjdk.x86_64:/usr/local/hadoop-0.20.2/bin:/usr/local/pig-0.6.0/bin:/home/ganga/bin

username=ganga
password=ganga1#
server=192.168.151.25
download_dir=/ganga/home/logs/
mkdir $download_dir

expect -c "
             # exp_internal 1 # uncomment for debugging
        spawn /usr/bin/scp "$username$server:/home/ganga/DYNAMIC/DELETES/*.log" $download_dir
             expect {
               "*Password:*" { send $password\r\n; interact }
               eof { exit }
             }
             exit
             "

cron_log:

Oct 12 11:13:01 hostname CROND[8304]: (ganga) CMD (/bin/sh /home/ganga/download.sh)

OS:

Redhat-linux 6.2

please help on this

Thanks,
Ganga

Hi Ganga,

This is probably because there are some environmental variables missing from the script, I'd be tempted to test it quickly by adding a line which loads the environment to test it try adding the following at the begining of your script.

source /etc/profile
source ~$username/.bash_profile

That is assuming I have the correct shells.

You can then identify which variables are missing and fix your script.

Regards

Dave

Hi Dave,

Thanks for reply.

I have tried as u told still its not working.
I trid at command like sh <script name > |at now + 2 mnts. its working manually.

i wrote into another file like below:

$ cat >file.sh
echo `sh <script name > |at now + 2 mnts`

i scheduled in cron

10 20 * * * /bin/sh /home/ganga/file.sh

it is fired and scheduled as at job.

but, again i am facing the same problem. I didn't understand what is going here. :wall: :wall:

Regards,

Gangadhar.