Mail, Scheduled Tasks
Mail Command
Basic syntax (after Mail goes in):
h Display the current mailing list
L displays a list of currently supported commands
D Delete the current message, D 1-100 Delete the 1th to 100th message
file displays the entire user's message store path and total number of messages
fn The pointer jumps to the nth message, for example F13 jumps to the 13th message
T read a message such as t22 read the 22nd e-mail
Top View the message header of the message that the current pointer is in
? View command parameter usage
Mail Write Mail
N read an e-mail, example N9 see 9th, just lose N, view the next message of the current pointer
Q Exit
4 type of Use:
1. Mail go to the interactive email interface and enter mail to edit mail
2. mail-s ' theme ' [email protected] Edit message content, Ctrl+d or. End
3. mail-s ' theme ' [email protected] </path/file file Redirection method
4. echo "Hello" | mail-s ' topic ' [Email Protected] Pipeline method
mail store location :
/var/spool/mail/username
at Command (the command that requires the ATD daemon to use the absolute path, because the command execution is related to path)
Command parameters:
- L Look at running job queue, quite with ATQ
- F read the list of commands to run at-f at.list 14:30 (at.list is a command list or script)
- C Look at the contents of the running job (running environment, configuration, etc.) example: At-c 2
- M When the task is completed, even if there is no output information, also to notify the user by email
Example:-M at now + 3day
Command format:
hh:mm Example: at 22:00
hh:mm Yyyy-mm-dd Example: at 22:00 2015-09-05
hh:mm [AM|PM] [month] [date] Example: at 04pm March
hh:mm [AM|PM] + number[minutes|hours|days]
Example: at now + 3days or at04pm + 3days
Batch: The system chooses to run the specified task when the resource is more idle, with the same command format as at
crontab: Recurring Task Scheduler, which needs to run a daemon: Crond
Parameters :
- u Specify the user name to establish the user's task
- e Edit
- L View Tasks
- R Delete All Tasks
format :
# Example of Job definition:
#.----------------Minute (0-59)
# |.-------------Hour (0-23)
# | | .----------Day of Month (1-31)
# | | |.-------month (1-12) OR jan,feb,mar,apr ...
# | | | | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
Minutes, hours, days, months, weeks
Special Symbols: * Accepted at all times
, representing the meaning of the separation period. Example: Execution 3:00 and 6:00 are 0 3,6 * * * command
- represents a time frame. Example: 8 to 20 minutes before 12 o'clock to do a job
208-12 * * *
/ n N. represents numbers, every n units interval, example: Executes every 5 minutes, */5 * * * *
/etc/cron.allow,/etc/cron.deny
Planning task tips:
Since crontab can only be accurate to minutes, there are 2 ways to implement a second-level task:
1. by the Sleep command, the number (in seconds) that can be divisible by 60 can be achieved. If the number of seconds in the interval is too small, such as 2 seconds to execute, you need to add the 60/2=30 clause to the crontab. It is not recommended to use this method
Example: required to perform cat/etc/fstab every 20 seconds
crontab-e Add:
* * * * * */usr/bin/cat/etc/fstab
* * * * * * sleep ;/usr/bin/cat/etc/fstab
* * * * * * sleep ;/usr/bin/cat/etc/fstab
Example 2:
*/1 * * * * sh/root/cron.sh
*/1 * * * * * sleep && sh/root/cron.sh
# Executes two times per minute every 30 seconds
2. through the Loop statement implementation
Example:
Crontab-e
* * * * source cron.sh
cron.sh as follows:
While True;do
Sleep 3;
Command
Done
Cycle once every 3 seconds, note that this is a dead loop script
crontab methods to execute multiple commands in the
Method 1:
*/30* * * * bin/sh/home/xyw/task1.sh
*/30* * * * bin/sh/home/xyw/task2.sh
Method 2
*/30* * * * BIN/SH/HOME/XYW/TASK1.SH; bin/sh/home/xyw/task2.sh
Method 3
*/30* * * * bin/sh/home/xyw/task1.sh && bin/sh/home/xyw/task2.sh
Method 4
*/30* * * * bin/sh/home/xyw/task1.sh | | bin/sh/home/xyw/task2.sh
crontab Special attention in the!!!!!
1. Crontab and environment variables
Don't assume that Cron knows the special circumstances you need, and it doesn't really know. So you have to make sure that you provide all the necessary path and environment variables in the shelll script, except for some auto-set global variables. So note the following 3 points:
1 write the global path when the file path is involved in the script;
2 when script execution is used with Java or other environment variables, the environment variables are introduced through the source command, such as:
Cat start_cbp.sh
#!/bin/sh
Source/etc/profile
Exportrun_conf=/home/d139/conf/platform/cbp/cbp_jboss.conf
/usr/local/jboss-4.0.5/bin/run.sh-c MeV &
3 When you manually execute the script OK, but the crontab is not executed. At this point, we must boldly suspect that environmental variables are the bane, and can try to directly introduce environmental variables in crontab to solve the problem. such as:
0 * * * *./etc/profile;/bin/sh/var/www/java/audit_no_count/bin/restart_audit.sh
2. Other issues to be aware of
1 The newly created cron job will not execute immediately, at least 2 minutes. If you restart Cron, it will be executed immediately.
2 after each JOB is completed, the system automatically sends the message to the current system user. It's very, very much, and it can even explode the whole system. Therefore, it is necessary to redirect after each JOB command: >/dev/null2>&1. The prerequisite is that the commands in the Job require normal output to be processed, such as appending to a particular log file.
3 when the crontab suddenly fails, you can try/etc/init.d/crond restart solve the problem. Or check the log to see if a job has execution/error tail-f/var/log/cron.
4 Don't run crontab-r. It removes the user's crontab file from the crontab directory (/var/spool/cron). All crontab of the user have been deleted.
5 in Crontab, the% has a special meaning, indicating the meaning of the line break. If you want to use the words must be escaped \%, such as the frequently used date ' +%y%m%d ' in the crontab will not be executed, should be replaced by the date ' +\%y\%m\%d '.
This article is from the "naïve Little Comrade" blog, please be sure to keep this source http://dengxi.blog.51cto.com/4804263/1692041
Linux Learning Path 6-mail, Scheduled Tasks