LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   From command line to a crontab script (https://www.linuxquestions.org/questions/programming-9/from-command-line-to-a-crontab-script-4175448664/)

alaios 02-05-2013 04:33 AM

From command line to a crontab script
 
Dear all,
I have been using the following command

rsync -rav -e ssh /home/user/Documents/Documents-Sensitive/ user@server:/home/user/Documents/

to do backups, in the terms of having a duplicate of the files somewhere else (server).

I would like now to turn this
1.into a script and
2. make it running every two days at 3:00 at night.
3. with low process and io priority (I think there is nice for processes and nice for io access)

Is that possible in Linux and how?
Could you please help me start filling in the missing parts of the puzzle?

Regards
Alex

unSpawn 02-05-2013 07:04 AM

Quote:

Originally Posted by alaios (Post 4884675)
Could you please help me start filling in the missing parts of the puzzle?

You recently asked about rsync and scripts, so instead of asking:
Quote:

Originally Posted by alaios (Post 4884675)
I would like now to turn this into a script and

may we expect you at least show use a rudimentary script with the actual commands you have used?
That would show what you understood of those threads and besides it's easier to correct.


Quote:

Originally Posted by alaios (Post 4884675)
make it running every two days at 3:00 at night.

See 'man 5 crontab' examples and post your proposed crontab line instead.


Quote:

Originally Posted by alaios (Post 4884675)
with low process and io priority (I think there is nice for processes and nice for io access)

Yes, there's 'nice' and 'renice' (as in 'renice +20 -p $$' ;-p). For I/O see 'man ionice'.
Do post the commands as you think you'll use it. (Also these days there's also cgroups but let's not get into that.)

alaios 02-05-2013 09:24 AM

Thanks I gave the script that I am using

rsync -rav -e ssh /home/user/Documents/Documents-Sensitive/ user@server:/home/user/Documents/

for all the rest some help is needed. I do not want ready made solutions but mostly where to look and then someone to validate if I did it correct

Alex

unSpawn 02-05-2013 09:29 AM

See 'man 5 crontab' examples and post your proposed crontab line instead.
There's 'nice' and 'renice' (as in 'renice +20 -p $$' ;-p). For I/O see 'man ionice'.
Do post the commands as you think you'll use it.

mlbx 02-06-2013 12:19 AM

You can get help with the part of the puzzle about crontab timing values at www.CronBuddy.com

alaios 03-28-2013 05:33 AM

Hi all,
would it be able to have cron to do something like that:

- Run the script two times a month (example, every second Saturday)
- Two specific dates of the months like the 10th and the 20th.

Regards
Alex

pan64 03-28-2013 06:02 AM

can you read the man page? just look for the string "every second Saturday"

alaios 03-28-2013 08:41 AM

nothing came

pan64 03-28-2013 10:45 AM

http://www.unix.com/man-page/Linux/5/crontab/

Habitual 03-28-2013 01:57 PM

Code:

#!/bin/bash
rsync -rav -e ssh /home/user/Documents/Documents-Sensitive/ user@server:/home/user/Documents/

save it, chmod 700 the script.
Your 3am cron will use it, so remember it's name and location.

mlbx 03-29-2013 01:47 AM

This cron simulator is now at http://www.dataphyx.com

mlbx 04-02-2013 06:05 AM

Quote:

Originally Posted by mlbx (Post 4885263)
You can get help with the part of the puzzle about crontab timing values at www.CronBuddy.com

This interactive cron sandbox is now at http://www.dataphyx.com

fredak 04-20-2013 04:02 AM

Quote:

Originally Posted by alaios (Post 4920426)
Hi all,
would it be able to have cron to do something like that:

- Run the script two times a month (example, every second Saturday)
- Two specific dates of the months like the 10th and the 20th.

Regards
Alex

Hi Alex

minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

if you put
50 13 8-14 * 6 your_task

it doesn't mean between the 8th and the 4th IF it is saturday (which is 6)
It will do : each day between the 8th and the 4th AND ALSO on every saturday

so what you will have to do is test the date
50 13 8-14 * * if [ `date +%u` = 6 ];then your_task;fi

in this case, your_task will be launched on the 2nd saturday or the month

put another line for the fourth saturday :
50 13 16-22 * * if [ `date +%u` = 6 ];then my_task;fi

Fredak


All times are GMT -5. The time now is 11:30 PM.