LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-22-2007, 07:33 PM   #1
just1812
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Rep: Reputation: 0
SSH Cron


Hi

I have created an ssh script with following ssh command in it.

ssh -i /home/user/.ssh/sshkey -l username server cat file.txt > /home/user/Desktop/file2.txt

This command works when I run it interavtively but doesn't work in cron.
I have also tried using the -n and -o batchmode=yes options.

When ran with cron it authenticates successfully but the command doesn't run on the server.

Any help would be great.
 
Old 11-22-2007, 11:40 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Most problems with Cron scripts are caused by the fact that Cron executes the scripts in a reduced shell, not the standard login shell. So something that works from the terminal or when run in a Bash script may not work when run from Cron. To resolve this, you have to give the full path to all binaries (except for the core utilities).

So for example, you would find where the ssh binary is installed:

Code:
tj@T-Bird:~$ which ssh
/usr/bin/ssh
And then modify your script to call it directly:

Code:
#!/bin/sh

# Path to ssh binary
SSHPATH="/usr/bin/ssh"

$SSHPATH -i /home/user/.ssh/sshkey -l username server cat file.txt > /home/user/Desktop/file2.txt
Again, that is the most common problem in situations like these with Cron. There might be some SSH-specific issue that I am not thinking of here that is causing the actual problem. But this is certainly worth a shot before you take the diagnosis any farther.
 
Old 11-23-2007, 01:41 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
not a networking question. moved to linux - software.
 
Old 11-23-2007, 06:17 PM   #4
just1812
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for your response!

I did try using the full path it never resolved my issue but I think it put me on the right path. I executed env from cron and piped it to a file. I compared the two environments and noticed that cron actually executes in /bin/sh I think this is the bourne shell. I know there is a way of setting the environment variables but I'm not sure how to off hand how to. I will look around and try to find out how to do this. Do you think this is the correct way to approach resolving this issue. I have tried many things and can't remember having such a hard time with what seems to be a very simple task.
 
  


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
Auto RSYNC Over SSH via Cron? carlosinfl Linux - General 1 09-10-2007 02:12 PM
CRON job creations w/ ssh w3developing Red Hat 5 02-26-2006 01:51 AM
Unusual ssh cron message jburford Linux - Security 4 10-31-2005 07:57 AM
Ssh Doesn't Work With Cron ? guano2 Linux - Networking 4 08-06-2005 12:57 AM
Cron Job not running ssh script karim0028 Linux - General 3 02-07-2005 12:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:22 PM.

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