Scheduled Tasks
1. Timing Task Basics
Writing format: Time-sharing week /bin/bash xxx.sh >/dev/null 2>&1 (or write to a file, if not, each scheduled task execution will generate a message to root, resulting in inode Full of problems). (Open mail Service will accumulate to mailboxfile/var/spool/mail/root(the time will be divided)If the mailbox is not opened, it will accumulate in the mailboxin this directory (/var/spool/postfix/maildrop)(all small files)
Illustrations:
650) this.width=650; "title=" QQ picture 20171011173400.png "Src=" https://s3.51cto.com/wyfs02/M01/A6/F0/ Wkiol1nd9zujqph3aaartdembwa839.png-wh_500x0-wm_3-wmp_4-s_3271535538.png "alt=" Wkiol1nd9zujqph3aaartdembwa839.png-wh_50 "/>
1. Common commands (and files)
crontab-l # Viewing scheduled tasks that have been set
crontab-r # empty all Scheduled Tasks
crontab-e # Write timed tasks (essentially writing this file /var/spool/cron/root)
# The system itself is timed tasks such as log splitting, configuration file /etc/crontab system poisoning after virus easy to write timed tasks here again
2. Dependent programs
crond # Note the difference between commands, easy to mix. (sshd,network is the daemon, need to start the program)
/sbin/service crond Start // start service
/sbin/service Crond Stop // Close service
/sbin/service crond Restart //Restart service
/sbin/service Crond Reload // reload configuration
/sbin/service crond Status // View service status
3. Standard writing format for timed tasks
A. now the command line test is feasible
B. put in script (absolute path required)
C. writing timed tasks ( tab Key not supported) (default no EXECUTE permission)
D. Check the timing task execution log and script effect to confirm normal execution. (/var/logl/cron)
write a few big mistakes:
A. timed tasks Multi-use script completion, if the command is written,the date +%f % has special meaning need \ swivel chair.
B. scripting timed task after fixed format >/dev/null 2>&1 (> file, only one exists)
C. Most environment variables are not recognized, so absolute path writing
D. package directory, to switch to the current directory, and then use a relative path does not error.
VI shortcut key? Improve the speed of writing, Master must!
:Wq
:q! # save, use every day, must be
G last line
GG on the front side
100gg to a specified line # large, jump lines
0 ^ Fast to the beginning of the line
$ Fast to end of line
o create a new line at the cursor position and go into input mode
O Previous Line
DD Delete cursor line (cut) # DG cut cursor to last line
P Paste (no need to go to input mode) # 100p paste
YY copy cursor current line # jump at one line level
U undo the previous action
/3306 Search content n continue search next n search # search function
v im- specific Properties
VI or vim shutdown unexpectedly, power off, disconnect, in the open file will be error. There is a . XXXX.SWP;E, ignoring the power outage, did not save the file, re-open the original file;R Recovery was not saved just now.
After the last line of colons R--- enter ---:wq---(view the original file, has been restored, and then open will repeat the error, delete hidden files can be)
E still error, also need to delete temporary files
D Delete both the temporary file and the local delete both can
2. Enterprise Applications
interview questions: Every night to pack the Web program, and the date of the command to back up files. (Packaged ACHF can be packaged with soft links)
Answer:
VI web_back.sh
! #/bin/bash
/bin/tar ZCHF web_backup$ (date +%f). tar.gz./www
Crontab-e
XX * * * */bin/bash/xxx/web_back.sh >/dev/null 2>&1
Analysis: The work of the scheduled tasks are usually early morning execution ~
This article is from the "Do Something Serious" blog, please keep this source http://edencheng.blog.51cto.com/12260487/1971495
Timed tasks (Crond in Linux)