Linux第十周

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

主机名

root@ubuntu:~# hostnamectl set-hostname hostname
root@ubuntu:~# vim /etc/hostname 
hostname
root@ubuntu:~# vim /etc/hosts
.....
127.0.1.1 hostname
.....

网卡名称

root@ubuntu:~# vim /etc/default/grub
.....
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

root@ubuntu:~# vim /etc/netplan/00-installer-config.yaml
......
    eth0:

root@ubuntu:~# grub-mkconfig -o /boot/grub/grub.cfg
root@ubuntu:~# reboot

网卡配置

root@gitlab:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    eth0:
      addresses:
      - 172.16.0.10/24
      gateway4: 172.16.0.254
  version: 2
2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。

expect

#!/bin/bash
. /etc/init.d/functions

rpm -q expect &> /dev/null || yum -y install expect &> /dev/null

PASS=123456

ssh-keygen -P "" -f /root/.ssh/id_rsa &> /dev/null
while read IP;do
expect &> /dev/null <<EOF
spawn ssh-copy-id root@$IP
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$PASS\n"  }
}
expect eof
EOF
action $IP
done < hosts.list

[root@localhost ~]# vim hosts.list 
172.16.0.10
172.16.0.20
172.16.0.30

shell

#!/bin/bash
. /etc/init.d/functions

rpm -q sshpass &> /dev/null || yum -y install sshpass &> /dev/null

HOSTS="
172.16.0.10
172.16.0.20
172.16.0.30
"
PASS=123456

ssh-keygen -P "" -f /root/.ssh/id_rsa &> /dev/null
for i in $HOSTS;do
{
    sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $i &> /dev/null && action $i
}&
done
wait
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[0]} && max=${nums[0]} && continue
    [ ${nums[$i]} -gt $max ] && max=${nums[$i]} && continue
    [ ${nums[$i]} -gt $min ] && min=${nums[$i]}
done

echo "${nums[*]}"
echo Max is $max
echo Min is $min
4、输入若干个数值存
#!/bin/bash

while true;do
    read -p ">> " num
    if [ $num == "q" ];then
        break
    fi
    echo $num
done
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值