linux定时任务crontab中service systemctl无效

linux定时任务crontab中service systemctl无效,原因是无环境变量$PATH
使环境变量在crontab中生效的方法:(建议第三种)
1.传参的方式
crontab中
*/1 * * * * /root/test/shell/test_crontab_env.sh “test_crontab_env”
test_crontab_env.sh 中
#!/bin/bash
echo "date +%Y-%m-%d" "%H:%M:%S $1" >> /tmp/test_crontab_env.file
2.在该shell脚本中定义环境变量
test_crontab_env.sh 中
#!/bin/bash
TEST_CRONTAB_ENV=test_crontab_env
echo "date +%Y-%m-%d" "%H:%M:%S $TEST_CRONTAB_ENV" >> /tmp/test_crontab_env.file
3.在该shell脚本中加载环境变量文件
#!/bin/bash
source /etc/profile
echo "date +%Y-%m-%d" "%H:%M:%S $TEST_CRONTAB_ENV" >> /tmp/test_crontab_env.file
4.
0 2 * * * . /etc/profile; sh /root/test/shell/test_crontab_env.sh

菜鸟教程第一页就有写这个问题
在这里插入图片描述

Debian重启crontab

/etc/init.d/cron restart
/etc/init.d/cron stop
/etc/init.d/cron start

在这里插入图片描述

在这里插入图片描述

service v2ray restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值