LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-07-2014, 11:46 AM   #1
Krook
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Rep: Reputation: Disabled
rsync crontab problems


Hi, I have a question regarding automating a rsync shell script to auto backup data from a server to local headless laptop i run debian on.

So far I have written a shell script called rsync.sh that works perfectly.

My crontab -e looks like this :

52 * * * * ~/Desktop/scripts/rsync.sh

Now, I have created ssh keys with passphrase to login to the remote server.

What I do now is : from my main laptop I ssh into the headless local laptop. I am not prompted for any ssh keyphrase. When I sh the script I get prompted for the passphrase, no idea why.

Problem is that the cronjob doesnŽt get carried out correctly and it isnŽt backing up any data.

in the terminal mail i have found this msg :

rom christoph@lapserver Mon Aug 25 00:40:01 2014
Envelope-to: christoph@lapserver
Delivery-date: Mon, 25 Aug 2014 00:40:01 +0200
From: root@lapserver (Cron Daemon)
To: christoph@lapserver
Subject: Cron <christoph@lapserver> sh /home/desktop/scripts/rsync.sh
Content-Type: text/plain; charset=UTF-8
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/christoph>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=christoph>
Date: Mon, 25 Aug 2014 00:40:01 +0200

sh: 0: Can't open /home/desktop/scripts/rsync.sh

What am I doing wrong ?
 
Old 11-07-2014, 12:15 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Are you sure you don't have any typos in your post? I don't see how "~/Desktop/scripts/rsync.sh" could possibly expand to "/home/desktop/scripts/rsync.sh". The capitalization doesn't match, and I doubt your user's home directory is /home.

What does your script look like?
 
Old 11-07-2014, 12:18 PM   #3
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,232
Blog Entries: 5

Rep: Reputation: 190Reputation: 190
shouldn't it be looking in /home/username/Desktop/scripts/rsync.sh ?

Maybe change your crontab to have the full path to the script.
is the directory Desktop capitalized or not ? case matters.
 
Old 11-07-2014, 12:29 PM   #4
Krook
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
thanks for your answers !

the script is :

#!/bin/bash
# a rsync script

rsync -azPe ssh #####@##################/krimac/sync /media/EXTHDD/sync



The full path is : /home/christoph/Desktop/scripts/rsync.sh

Now I understand that the path i put in crontab is wrong.

I have corrected this now to :

30 * * * * /home/christoph/Desktop/scripts/rsync.sh
 
Old 11-07-2014, 12:33 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You don't need -e ssh, that's the default. Are you missing a colon in your remote path though? It should be "user@ip:/krimac/sync"

You've mentioned three machines so far:
"a server"
"the local headless laptop"
"main laptop"

Which system can ssh into which without a password? Which system is trying to run the rsync script? Which system is it trying to connect to?
 
Old 11-07-2014, 12:55 PM   #6
Krook
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
the remote path is ok, I replaced the colon with a # when i blocked out the IP. the script works perfectly when manually executed.

the machine running the script is the headless (its not really headless, i just run it with closed lid and never touch it for anything) debian laptop. it syncs with the remote server. my main laptop is a MBP.

I can :

from the MBP ssh into the debian machine with ssh keys a preestablished and am not prompted with the passphrase.

run the script from the debian machine without being prompted for the passphrase of the ssh keys I previously set up.

what happens is if I ssh into the debian machine and then run the script this way i always have to enter the passphrase for the ssh keys.

thanks for your help
 
Old 11-07-2014, 01:08 PM   #7
Krook
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
ok cron now runs the script but i get an error msg for the keys....


Message 383:
From christoph@lapserver Fri Nov 07 19:05:03 2014
Envelope-to: christoph@lapserver
Delivery-date: Fri, 07 Nov 2014 19:05:03 +0100
From: root@lapserver (Cron Daemon)
To: christoph@lapserver
Subject: Cron <christoph@lapserver> /home/christoph/Desktop/scripts/rsync.sh
Content-Type: text/plain; charset=UTF-8
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/christoph>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=christoph>
Date: Fri, 07 Nov 2014 19:05:03 +0100

Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9]

is there any way i can include the passphrase of the ssh keys in the bash script ?
 
Old 11-07-2014, 01:15 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You should not use a passphrase when setting up the ssh keys for an application like this.
 
Old 11-07-2014, 01:16 PM   #9
Krook
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
OK, IŽll set up new keys with no passphrase and see If i can get it running.
 
Old 11-07-2014, 03:54 PM   #10
Krook
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
working with no problems at all after i got rid of the passphrases

a big THANKS to suicidaleggroll and farslayer for the help offered
 
  


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
Rsync and Crontab Setting up alaios Linux - General 9 02-28-2013 09:33 PM
notifications for rsync's done via crontab rjo98 Linux - Server 10 01-19-2012 04:24 AM
[SOLVED] rsync execution issue with crontab - Have given full path to rsync too!! Prabagaran Linux - Server 6 04-15-2011 02:39 AM
Backup with rsync and crontab gjblackford Linux - General 4 01-04-2007 09:53 AM
rsync in crontab loonykroons Linux - Software 3 11-28-2006 04:08 AM


All times are GMT -5. The time now is 06:12 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration