第十周作业

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 root@192.168.78.133
root@192.168.78.133'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 <<EOF
set timeout 20
spawn ssh $user@$ip
expect {
     "yes/no" { send "yes\n";exp_continue }
     "password" { send "$password\n" }
}
expect "#" { send "df -h\n" }
expect "#" { send "hostname\n" }
expect "#" { send "exit\n" }
expect eof
EOF
[root@localhost shell]#

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]#
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置) 2、编写脚本实现登陆远程主机。(使用expec...
    陌路残蝉阅读 1,690评论 1 0
  • 1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置) 主机名:root@template-ubunt...
    antikor阅读 1,456评论 1 0
  • 1、Ubuntu系统网络配置 1.1网卡名称的改变 1.2主机名称的更改 1.3IP地址的配置 2、编写脚本实现登...
    196_fendou阅读 1,553评论 2 0
  • 1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu...
    大唐百夫长阅读 536评论 0 0
  • 1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu...
    letsgoheat_c1dc阅读 1,326评论 0 0