Linux Experiment Report (3) - Scheduled Task Management - 2021.5.22

1. Configuration requirements:

  • Virtual machine VM15.0 and above
  • centos7.0 version
  • windows7 or windows10 host

2. The purpose of the experiment

  • Master the syntax for writing scheduled task statements
  • Master the skills of using scheduled tasks to improve execution efficiency
  • Learn how to schedule tasks in the production process

3. Experimental requirements: (Root)

A crontab scheduled task list is set up by the root user to complete the following tasks:

crontab -e
  1. The sshd service is automatically turned on at 6:30 every morning, and the sshd service is turned off at 23:30.
30      6        *      *        *      /usr/bin/systemctl start sshd
30      23       *      *        *      /usr/bin/systemctl stop sshd
  1. The data in the public directory /var/ftp/pub of the FTP server is emptied every 5 days.
0       *        */5    *        *      /usr/bin/rm –rf /var/ftp/pub/*
  1. Restart the httpd service every Saturday at 6:15.
15      6        *      *        6      /usr/bin/systemctl restart httpd
  1. Every Monday, Wednesday, and Friday at 22:30 pm, use the tar command to automatically back up the /etc/httpd directory.
30      22       *      *        1,3,5  /usr/bin/tar jcvf httpd.tar.bz2 /etc/httpd
  1. Configure a scheduled task for the 180xname user: execute /bin/echo hello at 13:40 every day
crontab -e -u 1802huangjie
# 40      13      *       *       *       /bin/echo hello
  1. Set a scheduled task for user lisi, copy the contents of the /etc/passwd file to the host directory at 23:55 every Sunday night, and save it as pwd.txt
crontab -e -u lisi
# 55	23      *       *       7       /usr/bin/cp /etc/passwd /home/lisi/pwd.txt
  1. Set up a scheduled task for user wangwu, backup /var/log/message to the log-bak directory in your home directory every 2 hours between 8:00 and 18:00 on weekdays
crontab -e -u wangwu
# *       8-18/2          *       *       *       /usr/bin/cp /var/log/message /home/wangwu/log-bak
  1. View the contents of the root user's scheduled tasks list
crontab -l
  1. View the contents of the scheduled tasks list of users zhangsan and lisi
# 查看用户zhangsan的计划任列表的内容
crontab -l -u zhangsan

# 查看用户lisi的计划任列表的内容
crontab -l -u lisi
  1. Delete the scheduled task of 180xname
crontab -r -u 1802huangjie

4. Previous: Linux Experiment Report (2) - Disk Storage Management

Linux Experiment Report (2) - Disk Storage Management

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325718008&siteId=291194637