ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.