1.创建shell脚本(在CommandSh目录下创建一个名为iwcap的shell文件)
touch /CommanSh/iwcap4.sh
2.编写shell脚本
vi iwcap4.sh
#!/bin/sh
result=`ifconfig | grep mon0 ` ---检查是否有名为mon0的端口,将返回结果赋值为result变量
date=$(date +%Y-%m-%d\ %X) ---获取系统时间
if [ "$result" = "" ]; then ----判断返回结果是否为空
iw phy phy0 interface add mon0 type monitor
sleep 2s
ifconfig mon0 up
sleep 1s
(iwcap4 -i mon0 -a 192.168.0.146 -p 10060 -t 60 -n 007&)
echo "$date mon0 create success " >> /CommandSh/CommandLog/iwcap4.log -----将输出日志不覆盖的写入/CommandSh/CommandLog/iwcap4.log文件中
else
echo "$date mon0 already exist " >> /CommandSh/CommandLog/iwcap4.log
fi
3.给写好的shell脚本添加可执行权限
chmod a+x /CommandSh/iwcap4.sh
4.指定crontab定时任务
crontab -e ----edit crontab
crontab -l -----list crontab
执行成功输出结果。