小编Her*_*ert的帖子

如果连接到特定的 wifi 网络,则仅运行 CRON 作业

我是在 Linux (Lubuntu) 上编写脚本的新手,但我想制作一个脚本,仅当我的笔记本电脑连接到我的家庭 wifi 时才运行 cron 作业。

这可能吗?

我想,我可以用 iwconfig 做一些事情,然后用 grep 从那里拉出 ESSID?

到目前为止,我试过这个,它似乎工作:

#!/bin/bash
# CRON, connected to specific WIFI
clear
netid=HOFF216
if iwconfig | grep $netid
then 
    clear   
    echo "True, we are connected to $netid"
    rsync ...........
else
    clear       
    echo "False, we are not connected to $netid"
fi
Run Code Online (Sandbox Code Playgroud)

cron wireless

2
推荐指数
1
解决办法
3203
查看次数

标签 统计

cron ×1

wireless ×1