Ubuntu与Centos不同,Ubuntu使用的是netplan来作为网卡的基础配置参数,并且使用的是yaml格式。在系统安装完成后,会自动生成如下的配置参数 /etc/netplan/00-installer-config.yaml
配置网卡ip地址和dns
# This is the network config written by ‘subiquity‘
network:
ethernets:
ens33:
dhcp4: false
addresses: [192.168.96.143/24]
gateway4: 192.168.96.2
nameservers:
addresses:
- 222.172.200.68
- 114.114.114.114
version: 2
确认dns地址配置正确
确认网关地址配置正确
网络连通性测试
重新登录shell,可以看到主机名已经修改。
系统默认并没有安装expect工具,需要通过yum源安装
编写脚本自动登录
#!/usr/bin/expect
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue}
"password" { send "$password\n" }
}
interact
#!/bin/bash
#================================================================
# Copyright (C) 2021 All rights reserved.
#
# FileName : expect.sh
# Author: : HuaGuobin
# CreateDate: 2021-05-25
# Decription:
#
#================================================================
ip=$1
user=$2
password=$3
if [ ! $# -eq 3 ];then
echo "Argv is error"
echo "Usage: $0 [IP] [USERNAME] [PASSWORD]"
exit
fi
expect <<EOF
set timeout 20
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
expect "]#" { send "ls / \n" }
expect "]#" { send "exit\n"}
expect eof
EOF
#!/bin/bash
#================================================================
# Copyright (C) 2021 All rights reserved.
#
# FileName : rand.sh
# Author: : HuaGuobin
# CreateDate: 2021-05-19
# Decription:
#
#================================================================
for i in {1..10};do
sum[$i]=$RANDOM
done
MAX=${sum[1]}
MIN=$MAX
for((j=1;j<10;j++));do
tem=${sum[j]}
[ $tem -gt $MAX ] && MAX=$tem
[ $tem -lt $MIN ] && MIN=$tem
echo ${sum[$j]}
done
echo MAX=$MAX
echo MIN=$MIN
#!/bin/bash
#================================================================
# Copyright (C) 2021 All rights reserved.
#
# FileName : read.sh
# Author: : HuaGuobin
# CreateDate: 2021-05-25
# Decription:
#
#================================================================
i=1
LastNumber=a
while [ $LastNumber != ‘q‘ ]
do
read -p "Please input The $i number:(press ‘q‘ exit) " NUM[$i]
LastNumber=${NUM[$i]}
if [ ! -n "$LastNumber" ];then LastNumber="a"; fi
[[ "${NUM[$i]}" =~ ^[1-9]+$ ]] && let i++ || ( [ $LastNumber != "q" ] && echo "You Input A Wrong Type,Please input again! ")
done
let j=i-1
for ((k=1;k<=$j;k++));do
for ((m=k;m<=$j;m++ ));do
if [ ${NUM[$k]} -lt ${NUM[$m]} ];then
SWP=${NUM[$k]}
NUM[$k]=${NUM[$m]}
NUM[$m]=$SWP
fi
done
done
echo "您输入的$j个数字,按照降序排列如下:"
for n in $(seq $j);do
echo ${NUM[$n]}
done
原文:https://blog.51cto.com/u_15131458/2813007