linux - 第一次写脚本,有两个问题 :嵌套,开机自启动
大家讲道理
大家讲道理 2017-04-17 16:22:45
[Linux讨论组]

第一次写.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
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
黄舟
  1. shell这么写语法是没有问题的;

  2. “busybox wget http://z7.hk/gbox/$file -O $file”这句即使地址错误,也会执行生成$file,所以判断不会去执行else;

  3. 将自启动代码写到rc.local是可以的,不过不同的linux release是否会启动执行rc.local。如systemctl启动方式默认就不会执行rc.local的。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号