linux shell 脚本写定时任务

本文介绍了一个用于创建无线监听端口mon0的Shell脚本实现过程,包括脚本创建、编写、权限设置及定时任务配置。通过判断mon0端口是否存在,不存在则进行创建,并启动监听。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

执行成功输出结果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值