1 /var/spool/cron/ 這個目錄下存放的是每一個用戶包括root的crontab任務,每一個任務以建立者的名字命名,好比tom建的crontab任務對應的文件就是/var/spool/cron/tom。通常一個用戶最多隻有一個crontab文件。linux
root用戶的cron,centos
2 /etc/crontabbash
[root@glinux-01 ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # 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 /星期 # | | | | | # * * * * * user-name command to be executed 用戶(默認是root) 執行的命令
格式:分,時,日,月,周 (*)表明全部ssh
備份任務直接複製配置文件。socket
0 3 * * 1 /user/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log 每日3點 和星期一執行此腳本 0 6 * * * echo "Good morning." >> /tmp/test.txt //注意單純echo,從屏幕上看不到任何輸出, 由於cron把任何輸出都email到root的信箱了。 42 4 1 * * root run-parts /etc/cron.monthly 每個月去執行/etc/cron.monthly內的腳本 注意: "run-parts"這個參數了,若是去掉這個參數的話,後面就能夠寫要運行的某個腳本名,而不是文件夾名。 0 4-6 1,2 * * /user/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log 每個月1,2日的4到6點執行腳本
問題:這個星期跟前面日月時的關係?指定日期不是指定星期全執行?編輯器
星期用來肯定哪一年執行。工具
查看狀態,綠色running表明啓動,dead表明沒啓動centos7
注意:寫任務計劃時,寫絕對路徑,以防未執行。spa
正確錯誤輸出寫入到文件裏rest
centos6和以前的版本使用的chkconfig
centos6 用的是sysV 服務 centos7 是systemd服務
chkconfig --level 3 network off 關閉network3級別 chkconfig --level 345 network off
添加服務,需將服務腳本放在/etc/init.d 下
在運行chkconfig --add [服務名]
刪除chkconfig --del [服務名]
contos7使用的systemd
systemctl list-units-files查看全部服務(包括target,socket)
systemctl list-units --all --type=service查看全部服務server(空格鍵下翻)
咱們這是服務開機啓動時,會提示一個路徑,這個路徑下顯示系統全部unit
ls /usr/lib/systemed/system
unit 相關命令
target介紹
cat /usr/lib/systemd/system/sshd.service //看install部分,就知道屬於哪一個target