linux it to schedule recurring tasks

Each user can set their own crontab file, to perform tasks automatically run the user's own needs. The user's own crontab file is located in / var / spool / cron / directory, but the user can not directly compile these files, the user must use the crontab command to edit it.

crontab command is used to install, remove or list the crontab task to drive the cron daemon.

Automatically schedule tasks, for example the user's process

// 1. Run the following command arrangements for the root user's crontab task

crontab -e

// 2. Write crontab task in vi, add the following line, 1st and 15th each month at 1:30 am for maintenance of the system state, reboot the system

30 1,15 * * shutdown -r +10>/dev/null 2>&1

// 3.2 point deletion daily morning / ftp / incoming / all files in the temp directory

00 02 * * * rm -rf /ftp/incoming/temp

// 4 daily 1:00 deleted / 7 days under the tmp directory is not modified in all subdirectories, not including the / tmp directory of the current and lost + found directory

00 01 * * * find /tmp ! -name .!  -name lost+found \

-type d -mtime +7 -exec /bin/rm -rf {} ';'

5 // Every morning 8 points / var / log / secure file content to [email protected]

0 8 * * * mail [email protected] </ var / log / secure

// 6. [email protected] send every two hours to the output of the command netstat -a

0 */2 * * * netsat -a | mail [email protected]

// 7. Open every day from 7 to 19:00 samba service

0 7 * * * service smb start

0 19 * * * service smb stop

// 8 every Sunday 14:00 to view / use the largest amount of the top ten users home directory

0 2 * * 0 root du -sh /home/* | sort -nr | head -10

After editing is completed save and exit vi, crontab such a task should be established,

You can use the following command to check crontab task

the -l crontab
----------------
Disclaimer: This article is the original article CSDN bloggers "Chow98", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_41138327/article/details/80811943

Guess you like

Origin www.cnblogs.com/xuanbjut/p/11441819.html