LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2012, 05:40 PM   #1
newtorhlinux
LQ Newbie
 
Registered: May 2012
Posts: 4

Rep: Reputation: Disabled
cronjob fails


Hi,
I have a script file to do an scp between two linux servers . The user is created in both server locally . Here is the script

#!/usr/bin/expect -f

set timeout 600
spawn scp "dbdkp.dmp" "mpdump@portalboxdb:."
expect {
-re ".*passphrase.*" {
exp_send "remsvrbkp"
exp_continue }
}
exit

When I run the script at the linux prompt, it works fine, copies the file to the remote server .

$./cpdmp.sh ( works fine)

But when I put it in crontab , and when it runs at the specified time, it gives the following error

spawn scp dbdkp.dmp mpdump@portalboxdb:.
Permission denied (publickey).
lost connection

Any suggestions ?
Thanks
 
Old 05-09-2012, 05:45 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
If you're clear-texting the passphrase into the script anyway, why not just skip the middleman and set up a fully passwordless login between the two servers. Then you can just scp like normal without having to use expect.

Last edited by suicidaleggroll; 05-09-2012 at 05:47 PM.
 
Old 05-09-2012, 05:48 PM   #3
newtorhlinux
LQ Newbie
 
Registered: May 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I know that could be the best solution, but that cant be done , as the linux admin wants to have a password. So I have to put it in the script .
 
Old 05-09-2012, 05:49 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
For what it's worth, I have an expect script that does something very similar, but looks quite different. I'm not an expect expert, so I can't really comment on what the differences are, but maybe you could try running it this way to see if you get different results

Code:
#!/usr/bin/expect

set timeout -1

spawn scp -p file user@ip:/home/file
expect *assword:
send "password\r"
expect eof

exit 0
 
Old 05-09-2012, 06:28 PM   #5
newtorhlinux
LQ Newbie
 
Registered: May 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Its the same . Giving error

Permission denied (publickey).
 
Old 05-09-2012, 07:33 PM   #6
newtorhlinux
LQ Newbie
 
Registered: May 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi, Some more observations. when I add the job to crontab as the user which has the script then the job wont run at all.

for example

crontab -e -u user1

15 16 * * * /users/user1/t.sh > /users/user1/t.log


the above one does not run at all .

Now I created using root


crontab -e

15 16 * * * /users/user1/t.sh > /users/user1/t.log


this is when I am getting the permission denied error . So i tired to just run the script and i have put a -v in the scp , just to see whats going on

#/users/user1/t.sh

here is what a portion of the verbose

debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection
send: spawn id exp6 not open
while executing
"send "remsvrbkp\r""
(file "/users/mpdump/t.sh" line 25)
 
Old 05-11-2012, 06:29 PM   #7
toothandnail
Member
 
Registered: Apr 2007
Location: Oxfordshire, UK
Distribution: Arch, Sparky, Salix64
Posts: 122

Rep: Reputation: 25
One possible option would be to use ssh-add to preload the passphrase. I use ssh/scp a lot, and use ssh-add at the start of a session so I don't have to keep typing a pass phrase over and over.

Paul.
 
Old 05-12-2012, 01:43 PM   #8
the_gripmaster
Member
 
Registered: Jul 2004
Location: VIC, Australia
Distribution: RHEL, CentOS, Ubuntu Server, Ubuntu
Posts: 364

Rep: Reputation: 38
An alternative is to use the sshpass command. In Ubuntu it is in the sshpass package. Should be the same for RHEL/CentOS/Fedora.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
CronJob jboy4 Linux - Newbie 3 02-27-2012 06:03 PM
cronjob help LinuxNeo Linux - Newbie 6 10-13-2010 11:54 PM
cronjob xser Linux - Software 6 07-27-2008 10:38 PM
Su in a cronjob michedlp Programming 3 11-06-2003 09:30 AM
cronjob FastEddy Linux - General 1 04-12-2003 10:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:38 AM.

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