LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cronjob fails (https://www.linuxquestions.org/questions/linux-newbie-8/cronjob-fails-944126/)

newtorhlinux 05-09-2012 04:40 PM

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

suicidaleggroll 05-09-2012 04:45 PM

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.

newtorhlinux 05-09-2012 04:48 PM

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 .

suicidaleggroll 05-09-2012 04:49 PM

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


newtorhlinux 05-09-2012 05:28 PM

Its the same . Giving error

Permission denied (publickey).

newtorhlinux 05-09-2012 06:33 PM

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)

toothandnail 05-11-2012 05:29 PM

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.

the_gripmaster 05-12-2012 12:43 PM

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.