[Solved] Crontab not working with scp

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read this

[Solved] Crontab not working with scp

Postby uzername on Mon Aug 12, 2013 2:36 pm

Can anyone see what might be wrong with this crontab entry? I'm intending to transfer my master keepass database file to my laptop every night, but it's not working. ssh is set up for password-free login with key, which works.

Code: Select all
12 21 * * * scp -P 1234 jeff@homer:~/.keepassx-db.kdb /home/jeff/
Last edited by uzername on Mon Aug 19, 2013 7:26 pm, edited 3 times in total.
Linux counter #317716
User avatar
uzername
Level 3
Level 3
 
Posts: 117
Joined: Mon Feb 25, 2013 4:41 pm

Linux Mint is funded by ads and donations.
 

Re: Crontab not working?

Postby MagicMint on Tue Aug 13, 2013 12:28 pm

If you mean /etc/crontab or any file entry in one of the cron directories within /etc, the following excerpt from man 5 crontab is relevant for you:
      “Unlike a user's crontab, this file has the username field, as used by /etc/crontab.”

This field, which is missing in your example, is the 6th one, thus the crontab entry should read:
Code: Select all
12 21 * * * jeff scp …


Furthermore, if this stands in another cron file, the name of the latter shouldn’t contain any dots — otherwise cron will skip the file altogether :evil: .
Minze, mint, menthe, menta, mento…

Avatar by PhotoZel at CrystalXP.net
User avatar
MagicMint
Level 1
Level 1
 
Posts: 16
Joined: Fri May 31, 2013 1:29 pm

Re: Crontab not working?

Postby uzername on Thu Aug 15, 2013 3:10 pm

Hmm, well, it's in the user's crontab, and I also put it in the root crontab with the user field. It fails both times.

I made a crontab test entry to mv a file, and that worked fine, so apparently cron is having some problem with scp or that particular command. Still trying to figure out what could be the issue, as I have pw-less login set up with ssh keys, which also works fine outside of cron.

>> edit: I think scp isn't reading the ssh keys for some reason, but I can't figure out why or how to get it to. I'm experimenting with the scp -i option, but not having luck so far.
Linux counter #317716
User avatar
uzername
Level 3
Level 3
 
Posts: 117
Joined: Mon Feb 25, 2013 4:41 pm

Re: Crontab not working with scp

Postby Habitual on Thu Aug 15, 2013 5:53 pm

-P port
Specifies the port to connect to on the remote host. Note that this option is written with a cap-
ital 'P', because -p is already reserved for preserving the times and modes of the file in rcp(1).

-p Preserves modification times, access times, and modes from the original file.

I don't know which you intended, but there it is.
YMMV
My DorkBlog
Cirrhus9.com - Managed HA VDSs and Scalable grid solutions.
User avatar
Habitual
Level 7
Level 7
 
Posts: 1924
Joined: Sun Nov 21, 2010 8:31 pm
Location: Under the hood

Re: Crontab not working with scp

Postby uzername on Thu Aug 15, 2013 7:03 pm

Habitual wrote:-P port
Specifies the port to connect to on the remote host. Note that this option is written with a cap-
ital 'P', because -p is already reserved for preserving the times and modes of the file in rcp(1).

-p Preserves modification times, access times, and modes from the original file.

I don't know which you intended, but there it is.
YMMV


Oops, my mistake in the original post. The actual crontab entry is "scpp," which I have as an alias for 'scp -P xxxx' (capital P). I just typed it wrong in the OP, thinking of the ssh option (which makes it totally stupid that scp uses -P :P).

Thanks for catching that, though - if it weren't for these keys, that would probably have been it. It's definitely a problem with key-based authentication, I just can't figure out how to get scp to use the key properly.
Linux counter #317716
User avatar
uzername
Level 3
Level 3
 
Posts: 117
Joined: Mon Feb 25, 2013 4:41 pm

Re: Crontab not working with scp

Postby MagicMint on Fri Aug 16, 2013 12:48 pm

uzername wrote:Oops, my mistake in the original post. The actual crontab entry is "scpp," which I have as an alias for 'scp -P xxxx' (capital P). I just typed it wrong in the OP, thinking of the ssh option (which makes it totally stupid that scp uses -P).


Just a thought: do you mean a shell alias or another command file of yours named “scpp” that calls the right “scp -P …” command on its own? I don’t think cron is intended to call aliases (unless it can be made to start in the right shell which knows the latter, perhaps) :roll:.
Minze, mint, menthe, menta, mento…

Avatar by PhotoZel at CrystalXP.net
User avatar
MagicMint
Level 1
Level 1
 
Posts: 16
Joined: Fri May 31, 2013 1:29 pm

Re: Crontab not working with scp

Postby uzername on Fri Aug 16, 2013 2:01 pm

MagicMint wrote:
uzername wrote:Oops, my mistake in the original post. The actual crontab entry is "scpp," which I have as an alias for 'scp -P xxxx' (capital P). I just typed it wrong in the OP, thinking of the ssh option (which makes it totally stupid that scp uses -P).


Just a thought: do you mean a shell alias or another command file of yours named “scpp” that calls the right “scp -P …” command on its own? I don’t think cron is intended to call aliases (unless it can be made to start in the right shell which knows the latter, perhaps) :roll:.


It's the same with the alias or the actual command. Going to remake my ssh keys and then specify them using the -i option, as per this thread w/same problem:
http://superuser.com/questions/264820/b ... command-li
Linux counter #317716
User avatar
uzername
Level 3
Level 3
 
Posts: 117
Joined: Mon Feb 25, 2013 4:41 pm

Re: Crontab not working with scp

Postby uzername on Mon Aug 19, 2013 7:26 pm

Ok, redid the keys, used the -i option, and now it works. Consider this case closed!
Linux counter #317716
User avatar
uzername
Level 3
Level 3
 
Posts: 117
Joined: Mon Feb 25, 2013 4:41 pm

Linux Mint is funded by ads and donations.
 

Return to Other topics

Who is online

Users browsing this forum: No registered users and 3 guests