在linux上用c來執行shell wifi登入限制篇
在linux底下先寫好.c檔
#vi go.c
=======================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
main()
{
int ok=0;
FILE *fop;
//弄個無窮迴圈讓系統在每5秒內自動找檔,沒東西就沒動作, 若找到了就執行 go.sh這個檔
while(ok==0){
sleep(5);
if((fopen("/home/sv/www/list","r")==NULL))
{
}
else
{
system("sh go.sh");
}
}
}
OK了之後執行 gcc go.c
會產生 a.out , 在linux下可執行檔 執行方法為
./a.out
a.out可以改成你想要的檔名
go.sh為linux的腳本 內容如下
=======================
test -e /home/sv/www/list && x=1 || x=0
if [ "$x" == "0" ]; then
exit 0
else
cat /home/sv/www/list > /home/sv/www/goiptables.rule
sh /home/sv/www/goiptables.rule
rm -fr /home/sv/www/list
fi
使用at 執行 或是開機就執行