crontab scheduled tasks

On centos7, the crontab service is named crond, which is enabled by default.

crontab -e for editing scheduled tasks. It takes effect immediately after saving and exiting.

The format is * * * * * user-name command.command is best to use the full path.

Case 1: Back up /srv/salt/ at 5:00 every Monday and place it in the /bak/salt directory named according to time.

[root@salt-server salt]# cat /scripts/salt_bak.sh
#!/bin/sh
cp -a /srv/salt /bak/salt/salt-`date "+%Y%m%d"`
tar cvf /bak/salt/salt-20180303.tar / bak / salt / salt-20180303 /
chmod +x /scripts/salt_bak.sh
[root@salt-server salt]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

00 5 * * 1 root /scripts/salt_bak.sh
systemctl restart crond

  

Case 2: Time Scheduled Task

30 04 * * * /usr/sbin/ntpdate 180.153.248.26 >/tmp/ntpsync.log

 

Guess you like

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