言西 发布的文章

shell多条件逻辑判断

用括号分隔,例子:

#!/bin/bash

a=asdf
b=23rr
c=23fsd
d=j32l4
e=j123
f=123

# a=asdf b=23r2r c=23fsdf e=j123 or j456
# or
# d=j32l4 f=123

if ([ $a = 3434sdf ] && [ $b = 23rr ] && [ $c = 23fsd ] && ([ $e = j123 ] || [ $e = j456 ])) || ([ $d = j32l4 ] && [ $f = 123 ])

then
   echo "执行"
else
   echo "不执行"
fi

shell 自动计算 bytes KB MB

自动计算 bytes 为 KB、MB、GB、TB,代码分2种,一种显示整数,一种显示2位小数。

#!/bin/sh
human_bytes(){
while read B dummy; do
  [ $B -lt 1024 ] && echo ${B} Bytes && break
  KB=$(((B+512)/1024))
  [ $KB -lt 1024 ] && echo ${KB} KiB && break
  MB=$(((KB+512)/1024))
  [ $MB -lt 1024 ] && echo ${MB} MiB && break
  GB=$(((MB+512)/1024))
  [ $GB -lt 1024 ] && echo ${GB} GiB && break
  echo $(((GB+512)/1024)) TiB
done
}

human_bytes_2(){
while read B dummy; do
  [ $B -lt 1024 ] && echo ${B} Bytes && break
  KB=$(echo "scale = 2; $B/1024" | bc | awk '{printf "%.2f", $0}')
  [ $(echo "$KB > 1024" | bc) -eq 0 ] && echo ${KB} KiB && break
  
  MB=$(echo "scale = 2; $KB/1024" | bc | awk '{printf "%.2f", $0}')
  [ $(echo "$MB > 1024" | bc) -eq 0 ] && echo ${MB} MiB && break
  
  GB=$(echo "scale = 2; $MB/1024" | bc | awk '{printf "%.2f", $0}')
  [ $(echo "$GB > 1024" | bc) -eq 0 ] && echo ${GB} GiB && break
  
  echo $(echo "scale = 2; $GB/1024" | bc | awk '{printf "%.2f", $0}') TiB
done
}

Proxmox VE单网卡多IP配置

Proxmox VE基于debian的,所以直接改/etc/network/interfaces文件,用service networking restart命令重启网络不用重启机器,如果用webui改会锁定配置文件,生成一个interfaces.new文件,重启机器才能生效。

auto lo eth0
iface lo inet loopback
iface eth0 inet manual

auto vmbr0
iface vmbr0 inet static
        address 118.7.34.69
        netmask 255.255.255.0
        gateway 118.7.34.1
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
iface vmbr0 inet6 static
    address  2f02:0190:0006:0001:0000:0000:0000:0844
    netmask  64
    gateway  2f02:0190:0006:0001:0000:0000:0000:0001

此方法适合安装好Proxmox VE没有自动生成vmr0的情况,需要手动添加vmr0虚机交换机,重点是把原网卡eth0改成manual,vmr0的IP改成物理IP,虚拟机直接填外网IP即可。

黑群晖 Active Backup for Business 套件激活方法

群晖 Active Backup for Business 套件使您可以备份无限的 Windows 端点、VMware、Hyper-V 和文件服务器

激活方法:

1.先安装Active Backup for Business 套件

2.再访问:

https://IP地址:5001/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=1&account=登陆用户名&passwd=登陆密码

3.再访问:

https://IP地址:5001/webapi/entry.cgi?api=SYNO.ActiveBackup.Activation&method=set&version=1&activated=true&serial_number="序列号"

激活完成!

外网访问映射5510端口即可。