Wangdake 发布的文章

#include <stdio.h>

//351302984184056
#define IMEI "35130298418405"

int getIMEICheckDigit(char *imei)
{
    int i, sum1 = 0, sum2 = 0, temp, result = 0;

    for (i = 0; i < 14; i++) {
        if (i % 2 == 0) {
            //奇数位和
            sum1 += imei[i] - '0';
        } else {
            //偶数位乘2 个位十位和
            temp = (imei[i] - '0') * 2;
            sum2 += temp;
            if (temp >= 10) {
                sum2 -= 9;
            }
        }
    }
    temp = (sum1 + sum2) % 10;
    if (temp != 0) {
        result = 10 - temp;
    }

    return result;
}

int main(int argc, char *agrv[])
{
    printf("IMEI %s check digit is %d\n", IMEI, getIMEICheckDigit(IMEI));

    return 0;
}

创建实例
映像:CentOS 7
保存私有密钥

登陆
用户名:opc
用户密钥:选择保存的私钥

切换root:sudo -i
修改root密码:passwd root
修改opc密码:passwd opc

密钥登陆
vi /etc/ssh/sshd_config
禁用密码登陆:PasswordAuthentication no
禁用root登陆:PermitRootLogin no
重启ssh:systemctl restart sshd

修改私钥密码:ssh-keygen -f private_key -p

设置时区:timedatectl set-timezone Asia/Shanghai

启动时间:

date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"system boot:%Y-%m-%d %H:%M:%S"

运行时间:

cat /proc/uptime | awk -F. '{run_days = $1 / 86400; run_hour = ($1 % 86400) / 3600; run_minute = ($1 % 3600) / 60; run_second = $1 % 60; printf("系统已运行:%d天%d时%d分%d秒\n", run_days, run_hour, run_minute, run_second)}'

0点重启:
vi /etc/crontab
0 0 * * * root reboot