Example
Example: Insert a record into a database every one minute.
1. Create a .sh file
----insertsms.sh---
mysql -N -u root -e "use database; INSERT INTO table1 (project_id,feedback_id, text)VALUES (5,201,'Thank you, I am ALWAYS happy with the service I receive from .......');"
2. Run command in the command line
# crontab -e
3. Append the following entry:
0-59 * * * * /root/ insertsms .sh
save the file
Field Definition
Example: Insert a record into a database every one minute.
1. Create a .sh file
----insertsms.sh---
mysql -N -u root -e "use database; INSERT INTO table1 (project_id,feedback_id, text)VALUES (5,201,'Thank you, I am ALWAYS happy with the service I receive from .......');"
2. Run command in the command line
# crontab -e
3. Append the following entry:
0-59 * * * * /root/ insertsms .sh
save the file
More Examples
To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command
Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh
Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php
Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl
Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand
* * * * * *
| | | | | |
| | | | | +-- Year (range: 1900-3000)
| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month (range: 1-31)
| +---------- Hour (range: 0-23)
+------------ Minute (range: 0-59)
Use special string to save time
Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability.
Special string | Meaning |
@reboot | Run once, at startup. |
@yearly | Run once a year, "0 0 1 1 *". |
@annually | (same as @yearly) |
@monthly | Run once a month, "0 0 1 * *". |
@weekly | Run once a week, "0 0 * * 0". |
@daily | Run once a day, "0 0 * * *". |
@midnight | (same as @daily) |
@hourly | Run once an hour, "0 * * * *". |
Run ntpdate every hour:
Make a backup everyday:
@hourly /path/to/ntpdate
Make a backup everyday:
@daily /path/to/backup/script.sh
Comments
Post a Comment