unable to scp files while running shell script through crontab
Guys,
I have one script it runs fine by itself but behave strangely when run through crontab. This script simply grabs files from one server (using scp) and puts it under some directly on host server.
I exported PATH in script and tried to do same in crontab as well but no luck.
Really appreciate if someone can throw in some ideas on how to fix this?
Thanks
Inder
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
SrcServer=xyz
Source=a/b/c
File=any
Dest=d/e/f
SrcUsr=usr
SrcPwd=pwd
Timestamp=`date +%Y%m%d_%H%M%S`
cd $Dest
if [ -f $File ];
then
echo "Taking Back up of old file...."
mv $File $File.$Timestamp
fi
cd $Dest
/usr/bin/expect -c "
spawn /usr/bin/scp -pr $SrcUsr@$SrcServer:$Source/$File .
expect {
"*password:*" { send $SrcPwd\r\n; interact }
eof { exit }
}
exit
"
echo "File Transfer Completed..."
|