美文网首页
Linux之服务和计划任务

Linux之服务和计划任务

作者: cws | 来源:发表于2016-07-12 20:03 被阅读32次

服务:

在后台运行的软件就叫服务
参数:
start
stop
restart

apache启动后默认降权

service httpd start实际调用的是/etc/init.d/httpd这个shell脚本
而/etc/init.d是软连接文件夹,实际在/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

添加服务:

将脚本放在/etc/init.d/下即可

若要自启则:

chkconfig --list   //查看chk管理的自启动项
chkconfig --add httpd   添加到chk管理里面
chkconfig --del httpd   将httpd移出chk管理
chkcofnig --level 35 httpd on  init的345将开启
chkcofnig --level 345 httpd off
/etc/rc.d/rc3.d和rc5.d里将有httpd

计划任务:

启动方式:
系统启动时将有一个脚本将cron服务开启,启动后cron命令会搜索全局型配置文件/etc/crontab和位于/var/spool/corn目录下以用户名命名的文件

cron:每分钟醒来依次查看当前是否有需要运行的命令,最小单位就是分钟

添加任务:

格式:分(0-59) 时 日 月 周(0-6) 命令

第一种方法:
crontab -e  //任何权限都可以运行这个命令,针对某个用户

[wyb@localhost spool]$ crontab -e   //进入编辑,实际是写入到/var/spool/cron/username这个文件中
no crontab for wyb - using an empty one
*/1 * * * * date >> /tmp/date.txt   //每一分钟都向date.txt写入
1 * * * * date >> /tmp/date1.txt        //在第一分钟时将数据写入
~
~
~
"/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权限,针对系统任务
vim /etc/crontab会以root权限执行,不推荐使用
01 * * * * 用户名 命令 date >> /tmp/date2.txt在每个小时的第一分钟执行

查看用户任务:

[wyb@localhost tmp]$ sudo cat /var/spool/cron/wyb   //用户的计划任务
*/1 * * * * date >> /tmp/date.txt
[wyb@localhost tmp]$ sudo tail -5 /etc/crontab   //系统计划任务
# |  |  |  .------- 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   //只能显示普通用户定义的任务
*/1 * * * * date >> /tmp/date.txt
[wyb@localhost tmp]$ crontab -r   //移除用户所有计划任务,不能移除系统定的计划任务,即不能移除在/etc/crontab中的任务
[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]$ 

相关文章

  • Linux之服务和计划任务

    服务: 在后台运行的软件就叫服务参数:startstoprestart apache启动后默认降权 添加服务: 若...

  • linux 系统计划任务cron学习慕课笔记

    linux 系统计划任务cron: 1:检查cron服务 -检查Crontab工具是否安装: -检查crond服务...

  • laravel使用scheduler实现计划任务

    传统的计划任务是使用linux的crontab,每次对计划任务进行修改都要上服务器处理,不方便且不安全。larav...

  • robfig/cron

    cron Linux中使用内置cron计划任务服务,按照约定的时间定时执行特定的任务(job)。cron服务启动后...

  • 使用Linux crontab命令自动重启服务

    循环运行的计划任务,Linux系统则是由cron/crond这个系统服务来控制的。Linux系统上面原本就有非常多...

  • linux之计划任务

    实现Linux定时任务有:cron、anacron、at等,这里主要介绍cron服务。 那计划任务指的是什么呢? ...

  • 20.Linux中的计划任务

    Linux中的计划任务At单次执行计划任务cron 计划任务的使用计划任务:在某个时段自动执行某个任务。 Linu...

  • Linux服务器守护进程方案及实现

    总体思路 在linux服务器新建无登录账号(/sbin/nologin/) 构建自动化启动进程脚本 新建计划任务定...

  • 开启计划任务

    Linux 开启计划任务 开启计划任务(指定某个文件在什么时间段启动运行) 1.开启计划任务: service c...

  • Linux笔记链接

    手动配置IP系统服务硬链接与软链接SSHDYUM,RPM与源码安装计划任务FTP日志轮转Linux系统内核删除文件...

网友评论

      本文标题:Linux之服务和计划任务

      本文链接:https://www.haomeiwen.com/subject/tfrsjttx.html