2176
command , shell script ,tool , crontab / Re: crontab แบบมีประโยชน์ ครับ เอาไว้ set ในรูปแบบต่างๆ
« on: มกราคม 23, 2011, 12:30:50 am »
Examples for the Hour column:
8 = one value: execute in the 8 AM hour
5,6,9 = multiple values: execute in the 5, 6, and 9 AM hours
5-8 = range: execute in each hour between 5-8 AM (inclusive)
*/2 = fractional: execute in every other hour. 0 (midnight), 2AM, 4AM, 6AM, etc
3-12/3 = fractional range: execute in every third hour between 3AM and 12PM: 3AM, 6AM, 9AM, 12PM
Example:
5 */3 * * 1-5 cd "desktop/fold1"; ./fold &
This will launch on the 5-minute mark, every third hour, every day, every month, but only on days of
the work week (Mon-Fri). It cd's to the Desktop/Folding folder #1, then launches the launch
script in nohup mode so folding will keep running.
Example:
20,50 * * Jan-May,7-12 Mon-Fri cd "desktop/fold4"; ./foldlaunchscript
This will launch on the 20 and 50-minute marks, every hour, every day, every month except June (IT
desktop-inspection month), but only on days of the work week (Mon-Fri). It cd's to the
Desktop/Folding folder #4 on your Quad-CPU PowerMac, then launches the launch script which checks
for already-running instances of Folding before trying to launch another copy.
Example:
@reboot cd "/usr/local/mysql"; ./bin/safe_mysqld &
This will launch on each reboot. It cd's to the proper mysql root folder, then launches mysql
with the safe startup script in nohup mode.
Example:
12 * * * * cd "desktop/fold2"; ./foldlaunchscript
This will launch on the 12-minute mark, every hour, every day, every month, every day of the week.
It cd's to the Desktop/Folding folder #2, then launches the launch script which checks for
already-running instances of Folding before trying to launch another copy.
Example:
1 10 13 * 5 ./hiddenfolder/jokescript
This will launch at 10:01 AM, on any Friday the 13th. It launches your virus script.
Example:
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday. It ends the world.
A special prefix (@AppleNotOnBattery ) can be added to the command line to only execute if the
laptop is running on external power - desktops are always plugged in when running, so a desktop will
always execute the command. This is an Apple extension, so it only works on Darwin (OSX) systems,
not Linux, BSD, or UNIX. I would expect it to work on x86 Darwin, but have no x86 laptop to test it
with. Using this command prefix on something that does not support it (like RedHat on a P4) will
cause an error.
Example:
45 23 * * * @AppleNotOnBattery ./Applications/Utilities/diskoptimizerscript
This will launch at 11:45 PM each day. It launches a disk optimizer, but only if your laptop is
plugged in to a power source.
8 = one value: execute in the 8 AM hour
5,6,9 = multiple values: execute in the 5, 6, and 9 AM hours
5-8 = range: execute in each hour between 5-8 AM (inclusive)
*/2 = fractional: execute in every other hour. 0 (midnight), 2AM, 4AM, 6AM, etc
3-12/3 = fractional range: execute in every third hour between 3AM and 12PM: 3AM, 6AM, 9AM, 12PM
Example:
5 */3 * * 1-5 cd "desktop/fold1"; ./fold &
This will launch on the 5-minute mark, every third hour, every day, every month, but only on days of
the work week (Mon-Fri). It cd's to the Desktop/Folding folder #1, then launches the launch
script in nohup mode so folding will keep running.
Example:
20,50 * * Jan-May,7-12 Mon-Fri cd "desktop/fold4"; ./foldlaunchscript
This will launch on the 20 and 50-minute marks, every hour, every day, every month except June (IT
desktop-inspection month), but only on days of the work week (Mon-Fri). It cd's to the
Desktop/Folding folder #4 on your Quad-CPU PowerMac, then launches the launch script which checks
for already-running instances of Folding before trying to launch another copy.
Example:
@reboot cd "/usr/local/mysql"; ./bin/safe_mysqld &
This will launch on each reboot. It cd's to the proper mysql root folder, then launches mysql
with the safe startup script in nohup mode.
Example:
12 * * * * cd "desktop/fold2"; ./foldlaunchscript
This will launch on the 12-minute mark, every hour, every day, every month, every day of the week.
It cd's to the Desktop/Folding folder #2, then launches the launch script which checks for
already-running instances of Folding before trying to launch another copy.
Example:
1 10 13 * 5 ./hiddenfolder/jokescript
This will launch at 10:01 AM, on any Friday the 13th. It launches your virus script.
Example:
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday. It ends the world.
A special prefix (@AppleNotOnBattery ) can be added to the command line to only execute if the
laptop is running on external power - desktops are always plugged in when running, so a desktop will
always execute the command. This is an Apple extension, so it only works on Darwin (OSX) systems,
not Linux, BSD, or UNIX. I would expect it to work on x86 Darwin, but have no x86 laptop to test it
with. Using this command prefix on something that does not support it (like RedHat on a P4) will
cause an error.
Example:
45 23 * * * @AppleNotOnBattery ./Applications/Utilities/diskoptimizerscript
This will launch at 11:45 PM each day. It launches a disk optimizer, but only if your laptop is
plugged in to a power source.