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 |
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.
|
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 .
|
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 |
Its the same . Giving error
Permission denied (publickey). |
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) |
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. |
An alternative is to use the sshpass command. In Ubuntu it is in the sshpass package. Should be the same for RHEL/CentOS/Fedora.
|
All times are GMT -5. The time now is 07:32 PM. |