1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置)
修改主机名 hostnamectl set-hostname ubstudy 修改网卡名称 vim /etc/default/grub GRUB_CMDLINE_LINUX="net.ifnames=0" 然后配置生效 grub-mkconfig -o /boot/grub/grub.cfg 网卡配置 配置静态地址 vim /etc/netplan/01-netcfg.yaml network: version: 2 renderer: networkd ethernets: eth0: addresses: [10.0.0.4/8] gateway4: 10.0.0.1 nameservers: addresses: [10.0.0.1,8.8.8.8]
2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。
expect模式 vim expect.ept set user [lindex $argv 0] set ip [lindex $argv 1 ] set passwd [lindex $argv 2] spawn ssh $user@$ip expect { "yes/no" { send "yes\n";exp_continue } "password" {send "$passwd\n"} } interact [root@oracle_machine_1 ~]# ./expect.ept root 10.0.0.3 123456 spawn ssh root@10.0.0.3 root@10.0.0.3's password: Last login: Fri May 21 19:32:42 2021 from 10.0.0.2 [root@oracle_machine_2 ~]# hostname oracle_machine_2 [root@oracle_machine_2 ~]#
shell 模式 vim ssh.sh read -p "please input ip:" IP read -p "please input user:" USER read -p "please input password:" PASSWD expect <<EOF set time_out 5 spawn ssh $USER@$IP expect { "yes/no" { send "yes\n";exp_continue } "password" { send "$PASSWD\n";exp_continue } } expect "~]#" { send "hostname \n" } expect eof EOF [root@oracle_machine_1 ~]# ./ssh.sh please input ip:10.0.0.3 please input user:root please input password:123456 spawn ssh root@10.0.0.3 root@10.0.0.3's password: Last login: Fri May 21 15:24:41 2021 from 10.0.0.2 [root@oracle_machine_2 ~]# hostname oracle_machine_2
3、生成10个随机数保存于数组中,并找出其最大值和最小值
vim max_min.sh #!/bin/bash declare -i min max declare -a num for ((i=0;i<10;i++));do num[$i]=$RANDOM [ $i -eq 0 ] && min=${num[$i]} && max=${num[$i]} && continue [ ${num[$i]} -gt $max ] && max=${num[$i]} [ ${num[$i]} -lt $min ] && min=${num[$i]} done echo "all numbers are ${num[*]}" echo "the max number is $max ,the min number is $min" [root@oracle_machine_1 ~]# ./max_min.sh all numbers are 11596 1687 14146 29255 13420 12497 10018 18805 13280 20314 the max number is 29255 ,the min number is 1687
4、输入若干个数值存入数组中,采用冒泡算法进行升序或降序排序
随机数值排序
[root@oracle_machine_1 ~]# vim nums.sh #!/bin/bash #Author:root #phone-number: #Version:1.0 #CreateTime:2021-05-21 15:53:32 #Description: declare -a nums declare -i zh read -p "please input number of random numbers(3-20):" num if [ $num -lt 20 ] & [ $num -gt 2 ] then for ((i=0;i<$num;i++))do nums[$i]=$RANDOM done echo "the array are ${nums[*]}" for ((k=0;k<$num;k++))do for ((j=k;j<$num;j++))do [ ${nums[$k]} -le ${nums[$j]} ] || zh=${nums[$k]} nums[$k]=${nums[$j]} nums[$j]=$zh done done echo "this is Ascending sort ,the array are ${nums[*]}" for ((k=0;k<$num;k++))do for ((j=k;j<$num;j++))do [ ${nums[$k]} -ge ${nums[$j]} ] || zh=${nums[$k]} nums[$k]=${nums[$j]} nums[$j]=$zh done done echo "this is descending sort ,the array are ${nums[*]}" else echo "the numbers is wrong,please input correct numbers" fi [root@oracle_machine_1 ~]# ./nums.sh please input number of random numbers(3-20):10 the array are 17089 6000 27944 3896 25470 5997 11533 21084 12028 22342 this is Ascending sort ,the array are 3896 5997 6000 11533 12028 17089 21084 22342 25470 27944 this is descending sort ,the array are 27944 25470 22342 21084 17089 12028 11533 6000 5997 3896
确定数值排序
[root@oracle_machine_1 ~]# cat num.sh #!/bin/bash #Author:root #phone-number: #Version:1.0 #CreateTime:2021-05-21 15:53:32 #Description: declare -a nums declare -i zh a b c=1 PS3="please choose sort method:" select MENU in Ascending descending exit;do case $REPLY in 1) a=0 while true ; do read -p "please input your number or input 1 to sort:" num if [ $num -eq $c ] then echo ${nums[*]} break fi nums[$a]=$num a=++a done for ((k=0;k<a;k++))do for ((j=k;j<a;j++))do [ ${nums[$k]} -le ${nums[$j]} ] || zh=${nums[$k]} nums[$k]=${nums[$j]} nums[$j]=$zh done done echo "this is Ascending sort ,the array are ${nums[*]}" break ;; 2) b=0 while true ; do read -p "please input your number or input 1 to sort:" num if [ $num -eq $c ] then echo ${nums[*]} break fi nums[$b]=$num b=++b done for ((k=0;k<b;k++))do for ((j=k;j<b;j++))do [ ${nums[$k]} -ge ${nums[$j]} ] || zh=${nums[$k]} nums[$k]=${nums[$j]} nums[$j]=$zh done done echo "this is Ascending sort ,the array are ${nums[*]}" break ;; 3) break ;; *) echo "this is error" ;; esac done [root@oracle_machine_1 ~]# ./num.sh 1) Ascending 2) descending 3) exit please choose sort method:1 please input your number or input 1 to sort:4 please input your number or input 1 to sort:5 please input your number or input 1 to sort:2 please input your number or input 1 to sort:1 4 5 2 this is Ascending sort ,the array are 2 4 5 [root@oracle_machine_1 ~]#