LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2007, 06:42 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
rsync in the background


I am considering using rsync in the background to mirror a RAM disk to hard drive but I know nothing about backgrounding of tasks (which should be done by script at boot time).

The idea is to run a cron job (or similar) every 15 seconds or so.

Can someone make suggestions about info or howto?

Thank you for your help.
 
Old 04-27-2007, 09:45 AM   #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
You can background any command using the "&" at the end of the command.

However if you're starting it with a startup/boot (init) script or with cron it will automatically be backgrounded because neither of those are initiated from a "terminal" (including console). You wouldn't need the "&" there.

Note that & backgrounds but if you closed the terminal it was on it would stop the background process because your shell would send a SIGHUP (hangup signal) to it. You can prevent this by running the "nohup" command at the beginning of the line. That tells it to ignore SIGHUP so it keeps running ieve if you closed your terminal. Here again this isn't necessary with init and cron jobs because as noted they are automatically backgrounded by the processes that called them rather than by a shell on a terminal.

You should be careful on how you write your script - ever 15 seconds might not give it time to complete one rsync before it did the next.

You can make the script a while loop and put the 15 seconds there (since cron isn't that granular).

#!/bin/bash
CNT=0
until [ $CNT -eq 4 ]
do /usr/bin/rsync ....
CNT=`/usr/bin/expr $CNT + 1`
/bin/sleep 15
done

You then tell cron to run the above script every minute. The 4 runs would let it run 4 times every minute (4 x 15 = 60). It would then restart the script. That way if something happened to the run 1 minute it would restart it again a minute later. You might want to restrict it to 3 runs a minute though so it doesn't do exactly 60 seconds - this will give it a breather between each cron run.
 
Old 04-28-2007, 09:09 AM   #3
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
Thank you for your very good answer.
 
  


Reply



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 server vs rsync over ssh humbletech99 Linux - Networking 1 10-18-2006 12:10 PM
running rsync from a background c program BassJunkie Programming 2 08-26-2005 05:38 AM
Change background in solaris and Xterm background also EvilAngel Solaris / OpenSolaris 2 01-31-2005 11:25 AM
Windows Rsync Upload to Linux Rsync - permissions inspleak Linux - Software 0 10-12-2004 02:49 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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