1849495 Members
7274 Online
104044 Solutions
New Discussion

scp cron

 
SOLVED
Go to solution
Martin Wells
Frequent Advisor

scp cron

I'm trying to scp some files from one server to another via a script. This script works fine when run from the command line but when its in cron I get the following errors and no file transfer

Executing ssh2 failed. Command:' ssh2 -l oracle -x -a -o passwordprompt %U@%H's password: -o nodelay yes -o authenticationnotify yes rnssupa -s sftp' System error message: 'No such file or directory'

I'm using the full path for the scp command?

This is on a N-Class server running HPUX11 and ssh version 2.1.0

Thanks
6 REPLIES 6
RAC_1
Honored Contributor

Re: scp cron

First thing, can you do ssh to other host without problems? Do you have private/public keys exchange set properly? If ssh has no problems, try as follows.

scp /dir/file user@otherhost:/path/where_to_copy.

Anil
There is no substitute to HARDWORK
Francisco J. Soler
Honored Contributor
Solution

Re: scp cron

Hi,
You must specify the full path of ssh2 or set the PATH variable at the begining of the script.

When execute from cron you must be careful with the enviroment variables.

Frank.
Linux?. Yes, of course.
Martin Wells
Frequent Advisor

Re: scp cron

I can ssh without issue and perform the scp command from the script when run manually and from the command line if I just use just the scp line of code?
Francisco J. Soler
Honored Contributor

Re: scp cron

Hi Martin, I don't understand very well your last query, but if it is a path problem, your command execution depends of path variable, if the user you are executing from, have the correct path you can execute they, if not you must specify the full path.

See the .profile (sh) or .login (csh) user files to know the user path variable.

Frank.
Linux?. Yes, of course.
RAC_1
Honored Contributor

Re: scp cron

What are the ssh versions installed on both systems?

Also did you try as I told you?

scp /dir/file user@otherhost:/path/where_to_copy.

Anil
There is no substitute to HARDWORK
Bill Hassell
Honored Contributor

Re: scp cron

Very common problem: works manually, fails in cron. cron does NOT login so your 'normal' environment is non-existant. This is your cron environment:

HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

So your cron job must have everything explicitly coded: full pathnames for scp and any directories or files, all env variables replaced with actual values, etc.


Bill Hassell, sysadmin