You are not logged in.

#1 2012-01-20 03:18:43

bwat47
Member
Registered: 2009-10-07
Posts: 638

[SOLVED] Running a monthly cron job

I'm a total noob when it comes to cron, and I have ready the wiki page and didn't see any relevant examples of doing this. I want to run a cron job once a month to create a file (touch /.readahead).

I have gathered I can put a script in /etc/cron.monthly and I have crond in my rc.conf. I'm a bit confused as to what I need to put in the script though. Would something like this be enough?

#!/bin/sh
touch /.readahead

Would I need to add anything else, would I need to use su or sudo in the script?

Last edited by bwat47 (2012-01-21 18:11:29)

Offline

#2 2012-01-20 03:21:08

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Running a monthly cron job

You can use the @monthly call in crontab...

man crontab

# edit: the wiki page is good too https://wiki.archlinux.org/index.php/Cr … tab_format

Last edited by jasonwryan (2012-01-20 03:23:32)


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2012-01-21 17:57:23

lastchancetosee
Member
From: Berlin
Registered: 2009-02-19
Posts: 131

Re: [SOLVED] Running a monthly cron job

Would I need to add anything else, would I need to use su or sudo in the script?

Short answer: No, any valid script is fine. However ...

If you save the script in /etc/cron.monthly it will be run by root (Check 'crontab -l' as root, you'll find the commands that execute those scripts), so if you want commands to be executed by another user you either put the script into their crontab with crontab -e or use su/sudo inside the script.

Stuff in /etc/cron.monthly will be executed whenever cron is running and more than one month has elapsed since it last ran. If you want to execute the script at a specific time/on a specific date, put the script directly into root's crontab (sudo crontab -e).

Last edited by lastchancetosee (2012-01-21 17:58:06)


My ship don't crash! She crashes, you crashed her!

Offline

#4 2012-01-21 18:11:11

bwat47
Member
Registered: 2009-10-07
Posts: 638

Re: [SOLVED] Running a monthly cron job

lastchancetosee wrote:

Would I need to add anything else, would I need to use su or sudo in the script?

Short answer: No, any valid script is fine. However ...

If you save the script in /etc/cron.monthly it will be run by root (Check 'crontab -l' as root, you'll find the commands that execute those scripts), so if you want commands to be executed by another user you either put the script into their crontab with crontab -e or use su/sudo inside the script.

Stuff in /etc/cron.monthly will be executed whenever cron is running and more than one month has elapsed since it last ran. If you want to execute the script at a specific time/on a specific date, put the script directly into root's crontab (sudo crontab -e).

Thanks!

Offline

Board footer

Powered by FluxBB