crontab中PATH的坑
2015-07-31 00:00
309 查看
摘要: crontab中PATH的坑
看报错信息, 应该是找不到lsof这个命令
查看系统的PATH路径:
里面是包含/usr/sbin的,这能解释为什么命令行运行正常了,那就是crontab的PATH的问题了
在crontab运行一个echo $PATH的脚本,结果如下
果真是crontab的原因
在man page里面找到
一、现象
在命令行里面能正常运行脚本,在crontab里面报错:lsof: No such file or directory
看报错信息, 应该是找不到lsof这个命令
二、排查
查看lsof命令的路径:$ type -a lsof lsof is /usr/bin/lsof
查看系统的PATH路径:
$ echo $PATH /usr/lib64/ccache:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/dell/srvadmin/bin:/bin
里面是包含/usr/sbin的,这能解释为什么命令行运行正常了,那就是crontab的PATH的问题了
在crontab运行一个echo $PATH的脚本,结果如下
/usr/bin:/bin
果真是crontab的原因
三、原因
$ man 5 crontab
在man page里面找到
Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab's owner. PATH is set to "/usr/bin:/bin". HOME, SHELL, and PATH may be overridden by settings in the crontab; LOGNAME is the user that the job is running from, and may not be changed.
四、解决办法
在脚本里面export PATH=/usr/sbin:$PATH, 或者把crontab改成* * * * * . /etc/profile; your command
相关文章推荐
- Linux socket 初步
- Android之使用Http协议实现文件上传功能
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- 菜鸟说给菜鸟听之Beginning Linux Programming——Chapter1(1)
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- 基于 Linux 集群环境上 GPFS 的问题诊断
- 谁是桌面王者?Win PK Linux三大镇山之宝
- vivi下重新调整分区
- Linux VS Unix:Linux欲一统天下 Unix不死