Actual production case
The production room self-built PPTP client is connected to the production room by dial-up, but once the client network is accidentally disconnected and then dialed again
Generates an IP conflict, so a script is written to monitor whether PPTP IP is multiple (2 IPs will be generated after a general conflict)
#!/bin/bash#author liuyueming. /etc/profile #开始没有加这个环境变量for i in {10..35}do n= ' ifconfig|grep 10.13.0.${i}|wc-l ' #循环取ip并计数 # E Cho ' Ifconfig|grep 10.13.0.${i} ' if [$n-gt 1] #如果同一个ip出现两次及大于1说明ip冲突需要清除 then for network in ' IP add|g Rep 10.13.0. $i |sed ' S#^.*global # #g ' #取出重复ip的网卡名删除掉 do IP addr flush $network done Fidone
Manual execution without error, but put crontab execution will error prompt command Ifconfig not find
the command line executes the script, but the crontab execution of the shell script is unsuccessful due to two causes
Workaround
1. Path issues
See if the path to execute the script in Crontab is correct. For example:
*/1 * * * * cd /mypath/;./my_shell.sh > /dev/null 2>&1
2. Environmental variable Problems cause
The command to add an environment variable file to the shell script is typically added to the second line of the script:
There are two ways to make an environment variable file effective:
. /etc/profile
Attention:. and/etc/profile spaces
source /etc/profile
Resolve command line execution shell script succeeds, but crontab execution fails