嗨,我写了下面的bash脚本:bash脚本不作为的cronjob工作
cat /home/xyz/wlandiscovery.sh
#!/bin/bash
DATE=`date +%d-%m-%Y__%H:%M:%S`
#Get the current standard interface e.g. eth0
INTERFACE=`route | grep '*' | awk '{print $8}'`
#Check if mac is available
if /usr/bin/arp-scan --interface $INTERFACE -l -r 5 | grep "xx:xx:xx:xx:xx:xx"
then
echo -e "$DATE AVAILABLE!" >> /home/xyz/wlandiscovery.log
else
echo -e "$DATE NOT AVAILABLE" >> /home/xyz/wlandiscovery.log
fi
exit 0
如果我运行这个和MAC可我得到“可用”,如果我断开设备它给“NOT可用“... ...按预期运行。
但是,如果我运行它的cronjob每隔5分钟我总是得到“不可用”:(Debian的系统上)
crontab -e
#......
*/5 * * * * /bin/bash /home/xyz/wlandiscovery.sh
请告诉我这里的问题?
不需要将'grep'管道到'awk':'awk'/ \ */{print $ 8}''也可以。 –
脚本的权限是什么? – Jhonathan