利用定時任務實現嵌入式下網絡卡狀態檢測

2021-06-19 18:43:19 字數 813 閱讀 8858

思路比較簡單,就是利用定時任務cron定時去執行乙個指令碼去檢測網格狀態。

首先在/var/spool/cron/root-crontab/建立相應的配置檔案:test.crontab(哪些時間段去執行什麼指令碼)

內容如下:

*/5  * * * * /usr/share/test.sh

就是說每隔5分鐘定時去執行/usr/share/test.sh這個指令碼

test.sh可以實現任何任務。在這裡是通過獲取自己的閘道器,然後去ping這個閘道器,如果能ping通則代表網路正常,不做任何事情。

如果ping不通,則重啟網絡卡。

conffile="/etc/network/inte***ces"

test -f $conffile || exit 0

ip_addr=`cat $conffile |grep gateway |sed 's/^.*gateway//g'`

ping -c 2 $ip_addr

tag=$?

if [ $tag == 1 ];then

/etc/init.d/network restart

fi

inte***ces 檔案是如下設定的:

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 10.17.1.227

netmask 255.255.0.0

gateway 10.17.0.253

spring boot 定時任務實現

scheduled 使用 scheduled 非常容易,直接建立乙個 spring boot 專案,並且新增 web 依賴 spring boot starter web,專案建立成功後,新增 enablescheduling 註解,開啟定時任務 enablescheduling 開啟定時任務 pu...

Spring定時任務實現

一 spring 定時任務 component enablescheduling 可以在啟動類上註解也可以在當前檔案 public class testschedule scheduled fixedrate 1000 10 public void runsecend scheduled fixed...

SpringBoot定時任務實現

靜態定時任務實現 基於註解來建立定時任務 configuration enablescheduling public class scheduletask 基於資料庫的動態定時任務實現 將定時任務配置在資料庫,啟動專案的時候,用mybatis讀取資料庫,例項化物件,並設定定時任務。如果需要新增,減少...