LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 03-26-2006, 04:43 AM   #1
joma
LQ Newbie
 
Registered: Feb 2005
Distribution: slackware 10.2
Posts: 11

Rep: Reputation: 0
Automatic rsync restart when dynamic IP changes


I want to synchronize a remote server to my own local one.
I have an ADSL with dynamic IP connection (12 hours changes)
How can I automatically restart rsync if IP changes while running this task?
 
Old 03-26-2006, 08:43 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
just a cron job to take care of it if there is nothing better there monitoring this...
Code:
#!/bin/bash
CURRENT_IP=$(/sbin/ifconfig eth0 | grep inet\ addr | cut -d: -f 2 | cut -d\  -f 1)
if [ "$CURRENT_IP" != "$(cat /tmp/current_ip)" ]
then 
  do_rsync_restart
  echo $CURRENT_IP > /tmp/current_ip
fi
just run something like that every minute, 5 minutes, hour or whatever you want.
 
Old 04-18-2006, 02:57 AM   #3
joma
LQ Newbie
 
Registered: Feb 2005
Distribution: slackware 10.2
Posts: 11

Original Poster
Rep: Reputation: 0
well,I still haven't solved the problem.
My rsync command from console is the following:
rsync -avz --include=kde-i18n-it-* --include=kde-i18n-en_GB-* --include=kde-i18n-de-* --include=koffice-l10n-it-* --include=koffice-l10n-de-* --include=koffice-l10n-en_GB-* --exclude=source/ --exclude=kdei/kde-i18n-* --exclude=kdei/koffice-l10n-* --delete --delete-after --delete-excluded --progress rsync://rsync.slackware.at/slackware/slackware-current /mnt/hda10/slackware/

When the IP-address changes (for example: xxx.2.68.158 to xxx.2.68.20)
I need to close the console, start a new one ,become superuser (root) and give again the rsync command.
The current IP I can gat with the following line

/sbin/ifconfig ppp0 | grep "inet addr"| cut -d':' -f2 | cut -d' ' -f1

now how can I create the /tmp/current_ip
create the cron job to verify it
and if it is necessary kill the rsync job and restart it again?
thanks in advance
 
Old 04-18-2006, 05:56 AM   #4
PDock
Member
 
Registered: Aug 2004
Distribution: Slack10 & curr. tried numerous
Posts: 189

Rep: Reputation: 36
Ok for the posted script to work you first need an existing current_ip file. Try

Code:
/sbin/ifconfig ppp0 | grep "inet addr"| cut -d':' -f2 | cut -d' ' -f1 > /tmp/current_ip
Of course once your copy of slackware-current mirrors the source server the time rsync needs to check for changes should be well under 12 hours.
 
Old 04-18-2006, 05:57 AM   #5
mdarby
Member
 
Registered: Nov 2004
Location: Columbus, Ohio
Distribution: Slackware-Current / Debian
Posts: 795

Rep: Reputation: 30
Create a bash script. In a new file (let's call it "/root/scripts/rsync_kde.sh") enter:

Code:
#!/bin/bash

$curr_ip=`/sbin/ifconfig ppp0 | grep "inet addr"| cut -d':' -f2 | cut -d' ' -f1`
$old_ip=`cat /tmp/curr_ip`

if["$curr_ip" -ne "$old_ip"]; then
  /usr/bin/rsync -avz --include=kde-i18n-it-* --include=kde-i18n-en_GB-* --include=kde-i18n-de-* --include=koffice-l10n-it-* --include=koffice-l10n-de-* --include=koffice-l10n-en_GB-* --exclude=source/ --exclude=kdei/kde-i18n-* --exclude=kdei/koffice-l10n-* --delete --delete-after --delete-excluded --progress rsync://rsync.slackware.at/slackware/slackware-current /mnt/hda10/slackware/
  echo $curr_ip > /tmp/curr_ip
fi
Now you have to chmod to 700:
Code:
chmod 700 /root/scripts/rsync_kde.sh
In root's crontab file enter a line like this:
Code:
*/2  0 * * * /root/scripts/rsync_kde.sh

Last edited by mdarby; 04-19-2006 at 10:12 AM.
 
Old 04-19-2006, 04:42 AM   #6
joma
LQ Newbie
 
Registered: Feb 2005
Distribution: slackware 10.2
Posts: 11

Original Poster
Rep: Reputation: 0
at the moment I get this error

root/scripts/rsync_kde.sh: line 6: if[xxx.2.68.168 -ne xxx.2.68.168]: command not found
 
Old 04-19-2006, 05:50 AM   #7
mdarby
Member
 
Registered: Nov 2004
Location: Columbus, Ohio
Distribution: Slackware-Current / Debian
Posts: 795

Rep: Reputation: 30
I've updated the original post.

Last edited by mdarby; 04-19-2006 at 10:08 AM.
 
  


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
how to shutdown xserver without automatic restart? Lotharster Linux - Newbie 4 02-08-2006 04:34 PM
Automatic restart cmgleipzig Linux - Newbie 6 07-14-2004 11:44 PM
Automatic dynamic DNS update Mc Leod Linux - Software 1 03-25-2004 05:07 PM
Automatic Restart Nezar Linux - General 11 09-24-2003 03:21 AM
Automatic restart redhat linux 8.0 poorni Linux - Hardware 1 08-05-2003 01:40 PM


All times are GMT -5. The time now is 03:55 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration