简体   繁体   English

cron 作业未在数字海洋液滴中以 root 用户身份运行

[英]cron job not running as root user in digital ocean droplet

I created this test bash script我创建了这个测试 bash 脚本

#! /bin/bash

echo "hello"

mkdir  "/karan/washere"

cron job i created, i want to run this cron job to run every min and want the log我创建的 cron 作业,我想运行此 cron 作业以每分钟运行一次并想要日志

#testing if cron job workes or not 
1 * * * * /user/local/bin/bash /root/test.sh  &> /root/crontest.log

I am signed in the droplet as root user我以 root 用户身份登录 Droplet

I also have given the permission for the script, using我也已经授予脚本许可,使用

sudo chmod u+x test.sh

I tried to log the syslog using我尝试使用记录系统日志

sudo grep CRON /var/log/syslog

but didn't show there also,但也没有在那里显示,

let me know if you need any more info or other context,如果您需要更多信息或其他背景信息,请告诉我,

cron uses sh to interpret the commands, not bash . cron使用sh来解释命令,而不是bash sh has less features and the &> is not valid in sh . sh的功能较少, &>sh中无效。

A better way for your line in the crontab would be:在 crontab 中你的行的一个更好的方法是:

1 * * * * /user/local/bin/bash /root/test.sh  >> /root/crontest.log 2>> /root/crontest.err

This will append to the logging instead of overwriting, and it will separate log from errors.这会将 append 写入日志而不是覆盖,并且它将日志与错误分开。

If you want, however, you can force cron to use bash instead of sh .但是,如果您愿意,可以强制cron使用bash而不是sh Your crontab should then be:你的 crontab 应该是:

SHELL=/bin/bash
#testing if cron job workes or not 
1 * * * * /user/local/bin/bash /root/test.sh  &> /root/crontest.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM