Cron job to run a script at the begining of the month - cron

I would like to write a cron job that has to run a PHP script on the 1st day of each month.
Can you please help me with this?
Thanks.

Add to crontab -e this:
0 0 1 * * php /path/to/script.php
Good luck!

Related

How to configure cron to run at multiple random intervals?

I'm working on a new project and I would like to setup a cron to run every 6-8 hours at a random minute. Any suggestions on the best way to achieve this would be greatly appreciated.
Let's run the cron every 6 hours:
0 */6 * * * /path/to/script.sh
Now, in your bash script:
#!/bin/bash
maxdelay=$((2*60)) # 2 hours converted to minutes
delay=$(($RANDOM%maxdelay)) # a random delay
(sleep $((delay*60)); /path/to/script.sh) & # background a subshell to wait, then run the script
You can also use anacron for RANDOM_DELAY feature.

how to schedule a cron job to run every second week

I have a cron command which I using currenly for run daily. I want to make it run every second week Monday morning 9AM. please advice
0 0 * * * curl -s -L web.url.com/user/adminNotifier
you can use this site to generate Cron command
http://crontab-generator.org/
hope this helps you

Crontab command not working

I know this question has been asked many, many times and I've done a lot of research but still I'm not able to run this extremely simple cron:
$ crontab -l
* * * * * /bin/date
This should, ideally, print the date every minute.
There is no cron.allow or cron.deny file, and the cron daemon is working:
ps -e | grep cron
1119 ? 00:00:00 cron
17646 ? 00:00:00 cron
Any idea what might be wrong?
Cron processes run in a separate subprocess of their own, so the output of a cron job will not be visible to you in your shell.
Instead, you will have to capture the output of your cron commands and save them. So, set your cronjob like:
* * * * * /bin/date >> /home/user/date.log
And now, if you will tail this log file, you will start seeing the result.

How to schedule cron job from shell script

I want to schedule a cron job in Linux by running a shell script.
The scenario is, I'm taking the time in HH:MM format in the shell script from the user and want to schedule a cron job from the shell script. I even want the cron job to be executed only once.
Thanks in advance...
For the crontab, you can do something like this:
cur=$(crontab -l)
new="$mm $hh * * * your_command"
echo "$cur$new" | crontab -
For one-shot, crontab is not the good candidate. Use at (note: your_command must be a file, e.g., a bash script)
at -f your_command $hh:$mm

Scheduling shell script in crontab

I have a shell script that I can run with root user this way:
root#vivid-15:~# ./backup.sh
It's on /root/backup.sh. Now, how do I schedule it on crontab to execute every day at 01:00 AM? I done this:
0 1 * * * root
But now I don't know how to proceed the command to do that.
Have you tried this? Also, a "1" in the hour field means 1am, not 1pm.
0 1 * * * root /root/backup.sh
Edit: changed the 13 (1pm) back to 1 (1am).
Crontab format:
MIN HOUR DAY MON WEEKDAY CMD
I don't know that you need to define what user you want it to run as when its in crontab -- commands will be run as the user who makes the entries with crontab -e. To create a cron process that runs as root, either login as root or set it up with $ sudo crontab -e
I think you're looking for something more like this:
0 1 * * * /root/backup.sh

Resources