LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 06-13-2012, 03:07 PM   #1
idhillon77
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Rep: Reputation: Disabled
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..."
 
Old 06-14-2012, 07:55 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
insert line: set -xv at the beginning and redirect the output (and stderr) of crontab entry into a file.
 
Old 06-14-2012, 04:03 PM   #3
idhillon77
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
I exported the error output and here's what i got

#!/bin/bash


export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

export PATH
+ export PATH

SrcServer=xyz
+ SrcServer=xyz
Source=a/b/c
+ Source=a/b/c
File=any
+ File=any
Dest=d/e/f
+ Dest=d/e/f
SrcUsr=usr
+ SrcUsr=usr
SrcPwd=pwd
+ SrcPwd=pwd

Timestamp=`date +%Y%m%d_%H%M%S`
date +%Y%m%d_%H%M%S
++ date +%Y%m%d_%H%M%S
+ Timestamp=20120614_165801

cd $Dest
+ cd /home/dest

if [ -f $File ];
then
echo "Taking Back up of old file...."
mv $File $File.$Timestamp
fi
+ '[' -f filename ']'

cd $Dest
+ cd /d/e/f

/usr/bin/expect -c "
spawn /usr/bin/scp -pr $SrcUsr@$SrcServer:$Source/$File .
expect {
"*password:*" { send $SrcPwd\r\n; interact }
eof { exit }
}
exit
"
+ /usr/bin/expect -c '
spawn /usr/bin/scp -pr usr@xyz:/d/e/f/filename .
expect {
*password:* { send pwd\r\n; interact }
eof { exit }
}
exit
'
echo "File Transfer Completed..."
+ echo 'File Transfer Completed...'
 
Old 06-15-2012, 08:33 AM   #4
idhillon77
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
any other ideas?
 
Old 06-15-2012, 10:59 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
from this log I cannot see anything, it looks like everything is ok. You need to look at the log of expect or log of scp somehow to find out where is the problem
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to use scp in a shell script Thaidog Programming 4 04-04-2011 03:10 PM
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 05:15 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
Running FTP inside Shell Script truncates files jbhanc0125 Red Hat 3 01-16-2004 11:37 AM
Shell script running via crontab problem. thetruethugg Linux - Software 13 12-19-2003 08:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration