Linux学习 -->解决Ubuntu系统上 No command 'crond' found

来源:互联网 发布:nginx 禁止某个域名 编辑:程序博客网 时间:2024/06/06 02:50

前两天,准备在Ubuntu服务器上,定时执行Gitlab备份的命令,如下所示
这里写图片描述

编辑 vi /etc/crontab 文件,添加如下定时脚本

# edited by ouyang 2017-8-11 添加定时任务,每天凌晨两点,执行gitlab备份0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1  

然而发现,凌晨2点并没有执行备份操作。

然后我去执行crontab 命令时提示 No command ‘crond’ found 无法执行。

root@ubuntu4146:/data/gitlabData/backups# crond reloadNo command 'crond' found, did you mean: Command 'cron' from package 'cron' (main)crond: command not found

这里写图片描述

1、安装 cron

执行如下命令

sudo apt-get install cron

命令运行如下:

root@ubuntu4146:/data/gitlabData/backups# sudo apt-get install cron正在读取软件包列表... 完成正在分析软件包的依赖关系树       正在读取状态信息... 完成       cron is already the newest version.下列软件包是自动安装的并且现在不需要了:  lib32asan0 lib32atomic1 lib32gcc-4.8-dev lib32gcc1 lib32gomp1 lib32itm1  lib32quadmath0 lib32stdc++-4.8-dev lib32stdc++6 libbonobo2-common  libc6-dev-x32 libc6-x32 libgnome2-common libltdl-dev liborbit-2-0 libssl-dev  libssl-doc libstdc++-4.8-dev libx32asan0 libx32atomic1 libx32gcc-4.8-dev  libx32gcc1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++-4.8-dev  libx32stdc++6 pkg-php-tools shtoolUse 'apt-get autoremove' to remove them.升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 310 个软件包未被升级。

2、 检测你的service路径

执行命令 which service

root@ubuntu4146:/data/gitlabData/backups# which service/usr/sbin/service

3、 执行相关 cron命令,带上路径 /usr/sbin/service

比如执行命令 sudo /usr/sbin/service cron start ,启动 cron 服务

root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron start start: Job is already running: cron

上面命令返回 Job is already running: cron 表示 cron命令早已经在运行中,
通常你可以通过执行命令 ps -ef | grep cron查看 cron命令是否正在运行

root@ubuntu4146:/data/gitlabData/backups# ps -ef | grep cronroot      1096     1  0 10:40 ?        00:00:00 cronroot      2155 62366  0 10:45 pts/1    00:00:00 grep --color=auto cron

执行命令 sudo /usr/sbin/service cron status , 查看crontab服务状态

root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron statuscron start/running, process 1096

执行命令 sudo /usr/sbin/service cron reload 重新 cron 服务配置

root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron reload

执行命令 sudo /usr/sbin/service cron restart , 重新启动 cron 服务

root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron restart cron stop/waitingcron start/running, process 1096

执行命令 sudo /usr/sbin/service cron stop , 停止 cron 服务

root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron stopcron stop/waiting

4、实际应用

将上面的gitlab备份任务 重新修改下。

# /etc/crontab: system-wide crontab# Unlike any other crontab you don't have to run the `crontab'# command to install the new version when you edit this file# and files in /etc/cron.d. These files also have username fields,# that none of the other crontabs do.SHELL=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin# m h dom mon dow user  command17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )## edited by ouyang 2017-8-11 添加定时任务,每天凌晨两点,执行gitlab备份0  2    * * *   root    /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1  #也可以按照如下所示的方法,定时执行 auto_backup.sh脚本,脚本内容就填写: /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 #0 2    * * *   root    /data/gitlabData/backups/auto_backup.sh -D 1    

这里写图片描述

然后重启 cron服务,这样就会正常运行定时任务了。

root@ubuntu4146:~# sudo /usr/sbin/service cron reloadroot@ubuntu4146:~# sudo /usr/sbin/service cron restart cron stop/waitingcron start/running, process 17738

相关链接地址
git学习——> Gitlab如何进行备份恢复与迁移?
http://blog.csdn.net/ouyang_peng/article/details/77070977


这里写图片描述

作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/77124597

如果本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行打赏。

这里写图片描述