服務(wù):
在后臺(tái)運(yùn)行的軟件就叫服務(wù)
參數(shù):
start
stop
restart
apache啟動(dòng)后默認(rèn)降權(quán)
service httpd start實(shí)際調(diào)用的是/etc/init.d/httpd這個(gè)shell腳本
而/etc/init.d是軟連接文件夾,實(shí)際在/etc/rc.d/init.d
[wyb@localhost ~]$ ls -al /etc/init.d
lrwxrwxrwx. 1 root root 11 Apr 11 02:54 /etc/init.d -> rc.d/init.d
添加服務(wù):
將腳本放在/etc/init.d/下即可
若要自啟則:
chkconfig --list //查看chk管理的自啟動(dòng)項(xiàng)
chkconfig --add httpd 添加到chk管理里面
chkconfig --del httpd 將httpd移出chk管理
chkcofnig --level 35 httpd on init的345將開(kāi)啟
chkcofnig --level 345 httpd off
/etc/rc.d/rc3.d和rc5.d里將有httpd
計(jì)劃任務(wù):
啟動(dòng)方式:
系統(tǒng)啟動(dòng)時(shí)將有一個(gè)腳本將cron服務(wù)開(kāi)啟,啟動(dòng)后cron命令會(huì)搜索全局型配置文件/etc/crontab和位于/var/spool/corn目錄下以用戶名命名的文件
cron:每分鐘醒來(lái)依次查看當(dāng)前是否有需要運(yùn)行的命令,最小單位就是分鐘
添加任務(wù):
格式:分(0-59) 時(shí) 日 月 周(0-6) 命令
第一種方法:
crontab -e //任何權(quán)限都可以運(yùn)行這個(gè)命令,針對(duì)某個(gè)用戶
[wyb@localhost spool]$ crontab -e //進(jìn)入編輯,實(shí)際是寫(xiě)入到/var/spool/cron/username這個(gè)文件中
no crontab for wyb - using an empty one
*/1 * * * * date >> /tmp/date.txt //每一分鐘都向date.txt寫(xiě)入
1 * * * * date >> /tmp/date1.txt //在第一分鐘時(shí)將數(shù)據(jù)寫(xiě)入
~
~
~
"/tmp/crontab.T8sDqC" 1L, 34C written
crontab: installing new crontab
[wyb@localhost spool]$ sudo ls /var/spool/cron/
wyb
[wyb@localhost spool]$ sudo cat /var/spool/cron/wyb
*/1 * * * * date >> /tmp/date.txt
1 * * * * date >> /tmp/date1.txt
[wyb@localhost spool]$
第二種方法:
編輯/etc/crontab文件 //要具有root權(quán)限,針對(duì)系統(tǒng)任務(wù)
vim /etc/crontab會(huì)以root權(quán)限執(zhí)行,不推薦使用
01 * * * * 用戶名 命令 date >> /tmp/date2.txt在每個(gè)小時(shí)的第一分鐘執(zhí)行
查看用戶任務(wù):
[wyb@localhost tmp]$ sudo cat /var/spool/cron/wyb //用戶的計(jì)劃任務(wù)
*/1 * * * * date >> /tmp/date.txt
[wyb@localhost tmp]$ sudo tail -5 /etc/crontab //系統(tǒng)計(jì)劃任務(wù)
# | | | .------- 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
*/1 * * * * wyb date >> /tmp/wyb.txt
[wyb@localhost tmp]$ crontab -l //只能顯示普通用戶定義的任務(wù)
*/1 * * * * date >> /tmp/date.txt
[wyb@localhost tmp]$ crontab -r //移除用戶所有計(jì)劃任務(wù),不能移除系統(tǒng)定的計(jì)劃任務(wù),即不能移除在/etc/crontab中的任務(wù)
[wyb@localhost tmp]$ crontab -l
no crontab for wyb
[wyb@localhost tmp]$ sudo tail -3 /etc/crontab
# | | | | |
# * * * * * user-name command to be executed
*/1 * * * * wyb date >> /tmp/wyb.txt
[wyb@localhost tmp]$