Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Crontab自定义shell执行cron_Linux_Bash_Shell_Cron - Fatal编程技术网

Linux Crontab自定义shell执行cron

Linux Crontab自定义shell执行cron,linux,bash,shell,cron,Linux,Bash,Shell,Cron,我想从自定义shell执行cron命令,如下所示: SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log #!/bin/bash -e #Script use to launch cron tasks set -e SHELL="/bin/bash -e" LOGDIR="/var/log/cronlauncher/" echo "$USER" > /tmp/test.log

我想从自定义shell执行cron命令,如下所示:

SHELL=/bin/cron-launcher.sh
* * * * * test  echo "toto" >> /tmp/shell.log
#!/bin/bash -e

#Script use to launch cron tasks

set -e

SHELL="/bin/bash -e"
LOGDIR="/var/log/cronlauncher/"

echo "$USER" > /tmp/test.log
#!/bin/bash

#Script use to launch cron tasks

SHELL="/bin/bash"
LOGDIR="/var/log/cronlauncher/"

#echo "$USER" >> /tmp/test.log
COMMAND="$2"
eval $COMMAND
问题是,如果我指定自己的shell,那么/tmp/shell.log文件是空的

我的自定义shell的内容如下所示:

SHELL=/bin/cron-launcher.sh
* * * * * test  echo "toto" >> /tmp/shell.log
#!/bin/bash -e

#Script use to launch cron tasks

set -e

SHELL="/bin/bash -e"
LOGDIR="/var/log/cronlauncher/"

echo "$USER" > /tmp/test.log
#!/bin/bash

#Script use to launch cron tasks

SHELL="/bin/bash"
LOGDIR="/var/log/cronlauncher/"

#echo "$USER" >> /tmp/test.log
COMMAND="$2"
eval $COMMAND
用于启动cron的用户可以很好地输出到文件/tmp/test.log,但是cron中的cron命令
echo“toto”
永远不会输出到文件
/tmp/shell.log

如何使自定义shell正确执行cron命令


那就是让
cron launcher.sh
脚本充当包装器

下面是my/var/log/cron的摘录:

12月26日15:55:01 bf7fe8653ac9 CROND[658]:(测试)CMD(echo“toto”>> /tmp/壳牌公司


通过执行解析到shell
cron launcher.sh

fac是来自cron的命令
echo“toto”>/tmp/shell.log

SHELL=/bin/cron-launcher.sh
*****测试回声“toto”>/tmp/shell.log

在shell
cron启动器中解析为
$2

因此,我不得不修改我的代码如下:

SHELL=/bin/cron-launcher.sh
* * * * * test  echo "toto" >> /tmp/shell.log
#!/bin/bash -e

#Script use to launch cron tasks

set -e

SHELL="/bin/bash -e"
LOGDIR="/var/log/cronlauncher/"

echo "$USER" > /tmp/test.log
#!/bin/bash

#Script use to launch cron tasks

SHELL="/bin/bash"
LOGDIR="/var/log/cronlauncher/"

#echo "$USER" >> /tmp/test.log
COMMAND="$2"
eval $COMMAND

cron launcher.sh
不是shell,它是一个bash脚本。这是真的,但我想让它像shell一样“运行”,或者更简单地说,充当shell之间的包装器1)和什么是
test
?2) 是
/bin/cron launcher.sh
列在
/etc/shells
-1)
测试是用户测试2)否它未列在
/etc/shells