ubuntu crontab 不执行的解决方法
在脚本文件的第二行添加下面一句即可
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
下面是分析解决问题的步骤:
1.不执行的原因是环境变量引起的
2.目前没有找到配置cron的默认环境变量配置方法
vim /etc/crontab 可以看到这个文件里的环境变量是正确的
3. * * * * * /root/test.sh >ifconfig.txt 2>&1 & 每分钟执行一次test.sh
test.sh的内容如下,可以看到输出结果环境变量是 /usr/bin:/bin
#!/bin/bash
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
ifconfig
echo $PATH
输出:
/root/test.sh: line 3: ifconfig: command not found
/usr/bin:/bin
4.查看ifconfig的位置
root@ubuntu:~# whereis ifconfig
ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
5.把test.sh脚本的第二行注释掉可以看到输出结果如下
eth0 Link encap:Ethernet HWaddr aa:00:04:00:0a:04
inet addr:192.168.1.60 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fef8:73b6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2093659 errors:0 dropped:0 overruns:0 frame:0
TX packets:1532815 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:519122457 (519.1 MB) TX bytes:447226592 (447.2 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:433596 errors:0 dropped:0 overruns:0 frame:0
TX packets:433596 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:23228192 (23.2 MB) TX bytes:23228192 (23.2 MB)
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
6.test.sh脚本只是临时改变了PATH的值,它只在当前脚本生效
ubuntu crontab 不执行的解决方法的更多相关文章
- windows8 8.1 安装完 ubuntu无法挂载 ntfs分区 解决方法
windows8 8.1 安装完 ubuntu无法挂载 ntfs分区 解决方法: 最近安装完发现8.1系统后,ubuntu无法加载以前的ntfs分区了,特别是我添加到了/etc/fstab里面了 导致 ...
- PowerShell因为在此系统中禁止执行脚本解决方法
PowerShell因为在此系统中禁止执行脚本解决方法 在Powershell直接脚本时会出现: 无法加载文件 ******.ps1,因为在此系统中禁止执行脚本.有关详细信息,请参阅 " ...
- (转)调用System.gc没有立即执行的解决方法
调用System.gc没有立即执行的解决方法 查看源码 当我们调用System.gc()的时候,其实并不会马上进行垃圾回收,甚至不一定会执行垃圾回收,查看系统源码可以看到 /** * Indicate ...
- ubuntu boot空间不足的解决方法
ubuntu boot空间不足的解决方法 2013年12月11日 11:11:39 yypony 阅读数:17000 标签: ubuntu内存boot内核更多 个人分类: linux_usageubu ...
- SQL Server作业没有执行的解决方法
SQL Server作业没有执行的解决方法 确保SQL Agent服务启动,并设置为自动启动,否则你的作业不会被执行 设置方法: 我的电脑--控制面板--管理工具--服务--右键 SQLSE ...
- WebBrowser 的 DocumentCompleted事件不执行的解决方法
原文:WebBrowser 的 DocumentCompleted事件不执行的解决方法 WebBrowser 的 DocumentCompleted事件不执行的解决方法: 使用WebBrowser的P ...
- ubuntu使用ssh登入不执行.bashrc解决方法
解决方法,可以直接输入 bash即可. 理解 bashrc 和 profile linux bashrc profile SEP 30TH, 2011 BY SUNTEYA 在一般的 linux 或者 ...
- Ubuntu几种常见乱码解决方法
一.网页中的flash乱码: ubuntu默认浏览器是Firefox,但是Ubuntu默认不安装像flash这种带版权的软件,所以当你浏览像youku或网页播放器时,这种带有 flash ...
- Ubuntu/Liinux睡眠无法唤醒解决方法:ACPI设置
最近给笔记本换了一个固态,顺便就重装了一下系统,版本是Ubuntu 20.10.装完之后各种功能基本都是正常的,触摸板轻触单击.双指右键等功能开箱即用.但是在安装完最新的Nvidia驱动之后就出现了问 ...
随机推荐
- Codeforces Round #365 (Div. 2) D.Mishka and Interesting sum 树状数组+离线
D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...
- c++ std::find函数
template <class InputIterator, class T>InputIterator find (InputIterator first,InputIterator l ...
- 资源(GitHub)
angular 文档 https://angular.cn/docs/ts/latest/quickstart.html http://sc.qq.com/fx/u?r=OfFE5AA ios h ...
- 使用Monkey对apk做稳定性测试
认识Monkey 官方文档:https://developer.android.com/studio/test/monkey.html 什么是Monkey? Monkey是Android中的一个命令行 ...
- mybatis分页插件使用注意
之前的项目用的数据库是mysql,在pom.xml引入这一个就能分页了. 后来又开了一个项目,使用的是oracle数据库,我写分页的时候发现不能实现,在网上找到资料说是必须要5.0以上的.我就导了这依 ...
- notepad++去空格空行技巧
选择视图显示所有字符,替换成空的就行
- LeetCode OJ:3Sum Closest(最接近的三数之和)
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- Agilent RF fundamentals (8) Oscillator Decisions
----------------------
- FLASH动作脚本详解
FLASH动作脚本详解 一.FLASH脚本基础入门讲解 二.按钮AS的编写 三.影片剪辑的AS编写 四.动态文本框 五.影片剪辑的拖拽 六.流程控制与循环语句 七.绘图及颜色的AS的编写 八.声音 A ...
- PostgreSQL java读取bytes字段
写入bytea: File img = new File("/tmp/eclipse.png"); fin = new FileInputStream(img); con = Dr ...