LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 01-07-2008, 08:58 AM   #1
Fairys
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Rep: Reputation: 0
CRON problem: (rsync: Failed to exec ssh: Permission denied (13))


Hi all,

Recently I created a script to rsync two servers. Script uses ssh to make it a bit secure and works fine when executed manually from prompt.
Nothing spectacular in there:
Code:
rsync -e "ssh -i $SSHKEY" $SOURCESRV/$SOURCEDIR $DESTDIR/$DESTDIR
(I asume that I do not have to convince you guys that vars are correct? ;-) )
as stated, this work good when I run it manualy from prompt.
But it does not works when executed from cron. What is wrong with this script? What did I forgot, of what I am NOT aware of?
As I use Webmin to administer my server, lazy ass I am, I know, when I run this job there manualy I get:
Code:
Output from command /some_correct_path/rsync.sh ..
rsync: Failed to exec ssh: Permission denied (13)
rsync error: error in IPC code (code 14) at pipe.c(86) [receiver=2.6.9]
rsync: writefd_unbuffered failed to write 4 bytes [receiver]: Broken pipe (32)
rsync error: error in IPC code (code 14) at io.c(1122) [receiver=2.6.9]
Is there anyone who could assist on this? All help is more then welcome :-)

cheerz and tnx in advance.
 
Old 01-07-2008, 02:17 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Jobs in cron don't have the same environment variables that ones you run from the command line do. This is because it isn't really "logged in" so runs a minimally configured environment.

The most common cause of problems is PATH. If your script doesn't know where "rsync" and "ssh" are it can't execute them. Try specifying full path to each of these commands in the script or setting them up as variables that have the full pathname so you just use the variable in the command line.

e.g.
export SSH=/usr/bin/ssh
export RSYNC=/usr/bin/rsync
$RSYNC -e "$SSH -i $SSHKEY" $SOURCESRV/$SOURCEDIR $DESTDIR/$DESTDIR
 
Old 01-08-2008, 03:11 AM   #3
Fairys
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Original Poster
Rep: Reputation: 0
not there yet...

Thank you jlightner for replay.
I heard about that PATH issue so I even 'improved' my script to print PATH so I can see whats there.
Code:
/sbin:/usr/sbin:/bin:/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
looks good for me.
Anyways I followed your advice and did tried two things:
1.
Code:
RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
2.
Code:
export RSYNC=/usr/bin/rsync
export SSH=/usr/bin/ssh
in both solutions I used your line:
Code:
$RSYNC -e "$SSH -i $SSHKEY" $SOURCESRV/$SOURCEDIR $DESTDIR/$DESTDIR
but I still get the same error...

Do you have any other ideas?
cheerz,
 
Old 01-08-2008, 09:35 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Is the cron job being run as the same user you run from at command line. (i.e. is it the root user when you're running from command line and is this in root's crontab?) ssh trusts are typically done per user.

Also you might want to add an echo line to verify all your variables are what you think they are in the script. Perhaps one of them isn't being set the way you think it is? (SOURCESRV, SOURCEDIR etc...)
 
Old 01-08-2008, 02:07 PM   #5
griffey
Member
 
Registered: Jan 2004
Location: East Central Illinois
Distribution: RHEL 4/5/6 and Fedora
Posts: 89

Rep: Reputation: 15
This may be making things redundant, and I'll be the first to admit I don't know exactly what is and isn't allowed to be listed as a cron event, but what if you created a text file, added the line of your command to it, made that file executable (a "script," even though it's a one-liner) and then called THAT from cron?

That is, make a text file, perhaps called "rsyncjob" with just this in it:
rsync -e "ssh -i $SSHKEY" $SOURCESRV/$SOURCEDIR $DESTDIR/$DESTDIR

Then "chmod +x rsyncjob."

Then in your crontab instead of the big drawn-out command, simply do:

15 12 * * 1-5 /home/path/to/rsyncjob

Again, if that's making things redundant and I am just showing my cron/script naivete, forgive me, but that's probably what I would try if I were faced with a similar situation.

Good luck.

Edited: Part of the reason I think this way is that I run rsnapshot, which is basically an rsync wrapper, and the script I have cron run also includes writing the date out to a log file, then running rsnapshot, then writing to the log file that it has finished, if that makes any sense...

G.--

Last edited by griffey; 01-08-2008 at 02:09 PM.
 
Old 01-14-2008, 02:36 AM   #6
Fairys
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Original Poster
Rep: Reputation: 0
hmmm...

Hi all,

First of all I would like to thank you for all advice.
Even all sugestions I see here are more or less familiar for me it looks like it is still something else that I overlooked.
Last aproach sugested by griffey is mine preferd aproach to solve a problem: minimize as possible to locate problem faster. jlightner says what I was kinda aware of and I totaly follow his path, I still not there...
Other problem I have with testing it, that it is a cron job so it runs now and then. and bigest problem is that it works manualy... ;-) So I will try to do some other tricks and see whats it wil lrusult in. I will keep you informed guys

cheerz!
 
Old 01-16-2008, 06:34 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You can temporarily set it in cron to run 'soon', then comment it out in crontab whilst you analyse the results eg if it's now 10:23, set crontab

30 10 * * * mytest.sh >/home/me/mytest.out 2>&1

let it run, then comment it out.
At the 2nd line of the shell file, use
set -xv
which will display all vars as they are used and their translations.
As mentioned, which user it runs as is also significant.
 
  


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
udevd - rmdir(/dev/.udev/failed) failed: Permission denied pbhj Slackware 20 03-21-2008 10:46 AM
Auto RSYNC Over SSH via Cron? carlosinfl Linux - General 1 09-10-2007 02:12 PM
Rsync: permission denied jevin Linux - General 3 04-13-2007 09:37 AM
rsync permission denied macadam Linux - Networking 0 06-18-2006 03:35 AM
Failed to send mail : Write failed : Permission denied shawnbishop Linux - Software 1 03-27-2006 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 08:06 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