1) Write the shell script:
[email protected] cvv]# cat test1.sh
#!/bin/sh
/bin/date>>/home/cvv/test.log
echo "Hello world!" by cvv54 ">>/home/cvv/test.log
Give executable permission:
[Email protected] cvv]# chmod 777 test1.sh
2) Join the scheduled task queue with Crontab
Create a new cron file, write a program or command that requires a timed execution "absolute path required":
[email protected] cvv]# cat Rootcron
50,52,54 3 4/home/cvv/test1.sh
51,53,55 3 4/usr/bin/whoami>>/home/cvv/test.log
Submit a task to Cron:
[Email protected] cvv]# crontab Rootcron
To view tasks:
[Email protected] cvv]# crontab-l
#11月3日周四14点50-55 points Execute command
50,52,54 3 4/home/cvv/test1.sh
51,53,55 3 4/usr/bin/whoami>>/home/cvv/test.log
After the task is finished, delete:
[Email protected] cvv]# crontab-f
"Crontab usage: usage:crontab [-u user] File
crontab [-u user] [-e |-l |-r]
(default operation is replace, per 1003.2)
-E (Edit user ' s crontab)
-L (list user ' s crontab)
-R (Delete user ' s crontab)
-I (Prompt before deleting user ' s crontab)
-S (selinux context) "
The basic format of the crontab file is as follows
* * * * * command
Time-of-day months and weeks commands "
3) View Job completion status
[email protected] cvv]# cat Test.log
Hello World! by cvv54
Reference: http://www.jb51.net/LINUXjishu/19905.html
Http://blog.sina.com.cn/s/blog_7db69afe01017eof.html
Linux timed Task execution