cron job helpz

Soldato
Joined
7 Jan 2007
Posts
10,607
Location
Sussex, UK
If I wanted to run one script every week on a Saturday at 19:30 and again on Monday at 21:00 (for every week of the year) what is the command to do that?
 
Edit the crontab with crontab -e and add:


Code:
30 19 * * 6 /usr/bin/oxy > /dev/null
0 21 * * 1 /usr/bin/oxy > /dev/null

You could send the output to a log file if you need it rather than to null. Also double check that crond is running.
 
hhhmmm I was hoping I could combine them on one line.

I'm actually going to be setting this up on my web hosting using cpanel.

Potentially I'm going to have a 100 lines by the look of it. Is this bad?
 
There's no way to combine both those times into a single cron entry sadly :(

Well, you could make a cron job to run every 30 minutes and then make the script check if the time is 19:30 or 21:30 and decide if it should continue or not. Not very efficient though.

No real issue with having 100 cron entries, it isn't ideal but so long as your web host doesn't enforce restrictions it should be ok.
 
i'm trying to learn php and what I'm thinking might be a way of doing it is to:

PHP:
$d=date("D");


if ($d=="Wed") {

                $dayofweek = date('D', strtotime('next saturday'));

                $day = date('d', strtotime('next saturday'));

                $month = date('m', strtotime('next saturday'));

                $year  = date('Y', strtotime('next saturday'));
                
                echo $dayofweek . $day . $month . $year;

} if ($d="Sat") {

$day = date('D', strtotime('next wednesday'));

$dayofweek = date('d', strtotime('next wednesday'));

$month = date('m', strtotime('next wednesday'));

$year  = date('Y', strtotime('next wednesday'));    
    
    
}

?>

Now I'm using cron to exec on say Weds at 19:30 the script will then notice it's weds and (when the script is built) insert the year, month, day and hour and mins into a new row in my mysql table for the correct if statement.

Does this seem logical?
 
Back
Top Bottom