第十周作业

1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置)

主机名

修改主机名
hostnamectl set-hostname ubuntu

网卡名称

默认ubuntu的网卡名称和 CentOS 7 类似,如:ens33,ens38等
修改网卡名称为传统命名方式:

#修改配置文件为下面形式
root@ubuntu1804:~#vi /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
#或者sed修改
root@ubuntu1804:~# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#'
/etc/default/grub
#生效新的grub.cfg文件
root@ubuntu1804:~# grub-mkconfig -o /boot/grub/grub.cfg
#或者
root@ubuntu1804:~# update-grub
root@ubuntu1804:~# grep net.ifnames /boot/grub/grub.cfg
linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-8c14-
fe1a48ba153c ro net.ifnames=0
linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro net.ifnames=0
linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0
linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro net.ifnames=0
linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0
#重启生效
root@ubuntu1804:~# reboot

2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。

expct实现远程登录

#!/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
";exp_continue }
	"password" { send "$password
" }
}
interact

shell实现远程登录

#!/bin/bash
ip=$1
user=$2
password=$3
expect <<EOF
set timeout 10
spawn ssh $user@$ip
expect {
	"yes/no" { send "yes
";exp_continue }
	"password" { send "$password
" }
}
expect "]#" { send "hostname -I
" }
expect "]#" { send "exit
" }
expect eof
EOF

3、生成10个随机数保存于数组中,并找出其最大值和最小值

#!/bin/bash 
declare -i min max 
declare -a nums 
for ((i=0;i<10;i++));do 
nums[$i]=$RANDOM 
[ $i -eq 0 ] && min=${nums[$i]} && max=${nums[$i]}&& continue 
[ ${nums[$i]} -gt $max ] && max=${nums[$i]} 
[ ${nums[$i]} -lt $min ] && min=${nums[$i]} 
done 
echo “All numbers are ${nums[*]}” 
echo Max is $max 
echo Min is $min

4、输入若干个数值存

declare -a nums
read -p "请输入生成随机数个数:" number
for (( i=0;i<$number;i++ ));do
	nums[$i]=$RANDOM
done
echo "before sort:${nums[*]}"
declare -i n=$number
for (( i=0;i<n-1;i++ ));do
    for ((j=0;j<n-1;j++));do
        let next=$j+1
	if (( ${nums[$j]} > ${nums[$next]} ));then
          tmp=${nums[$next]}
	  nums[$next]=${nums[$j]}
	  nums[$j]=$tmp
	fi
    done
done
echo "after sort:${nums[*]}"
echo "the Min integer is ${nums[0]},the max integer is ${nums[$(( n-1 ))]}"
原文地址:https://www.cnblogs.com/qiaokaixin/p/14871790.html