第十周作业

1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置)
#修改主机名
yan@ubuntu-master:~$ cat /etc/hostname
ubuntu-master
yan@ubuntu-master:~$

#修改网卡名称
~$ sudo vim /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
# 更新配置
~$ sudo update-grub
# 重启服务器
~$ sudo reboot

2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。
# expect 方式
[root@localhost shell]# cat test
#!/usr/bin/expect
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
set timeout 10

spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n"}
}
puts "\n********************************************************************"
puts "\n                 WELCOME TO GUANGDONG ^V^"
puts "\n********************************************************************"
send "exit\n"
expect eof
[root@localhost shell]# ./test 192.168.78.133 root 123456
spawn ssh [email protected]
[email protected]'s password:
********************************************************************

                 WELCOME TO GUANGDONG ^V^

********************************************************************

Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun Jan 31 08:10:40 2021 from 192.168.78.133
[root@localhost ~]# 



## sehll 调用expect
[root@localhost shell]# cat test.sh
#!/bin/bash
ip=$1
user=$2
password=$3
expect <
3、生成10个随机数保存于数组中,并找出其最大值和最小值
[root@localhost shell]# cat test3.sh
#!/bin/bash

declare -i min max
declare -a nums

for ((i=0;i<10;i++));do
nums[$i]=$RANDOM
[[ $i -eq 0 ]] && min=${nums[0]} && max=${nums[0]}&& 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
[root@localhost shell]# ./test3.sh
All numbers are 12478 17245 17390 25393 11390 17395 18174 2169 31725 21147
Max is 31725
Min is 2169
[root@localhost shell]#

4、输入若干个数值存入数组中,采用冒泡算法进行升序或降序排序
[root@localhost shell]# cat arrs.sh
#!/bin/bash

echo "please  input number list"

read -a arrs

for (( i=0; i<${#arrs[*]}; i=i+1 ))
do
        for (( j=0; j<${#arrs[*]}-1; j=j+1 ))
        do
                if [[ ${arrs[j]} -gt ${arrs[j+1]} ]]; then
                        tmp=${arrs[j]}
                        arrs[j]=${arrs[j+1]}
                        arrs[j+1]=${tmp}
                fi

        done

done

echo ${arrs[@]}
[root@localhost shell]#

[root@localhost shell]# ./arrs.sh
please  input number list
9 888 483 5849 288392 349342 134 32 341
9 32 134 341 483 888 5849 288392 349342
[root@localhost shell]#

你可能感兴趣的:(第十周作业)