Linux的课堂便利脚本
上课的时,因为教室机总会重新重启,有时候就要重配网卡yum源和下载一些辅助工具,这里写一个脚本省去冗杂的过程
if [[]]可以防止unary operator expected的报错
nmcli device connect eno16777728 可以快速配网
复制以下代码
#!/bin/bash
echo ' this is a convenient sh '
echo ' author supermao'
read -p 'please configure host-only network video 192.168.10.0/24 and link image file:(yes/no)' choice
if [[ $choice = yes ]];then
nmcli connection delete supermao &> /dev/null
nmcli connection add con-name supermao ifname $(ip a | grep BROADCAST| cut -d : -f2) type ethernet &> /dev/null
nmcli connection modify supermao ipv4.method manual ipv4.address 192.168.10.100/24 &> /dev/null
echo 'address 192.168.10.100/24 configure network is ok'
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/local.repo << q
[centos]
name=centos
baseurl=file:///media
gpgcheck=0
enabled=1
q
if [[ $(tail -n 1 /etc/fstab) = '/dev/cdrom /media iso9660 defaults 0 0' ]];then
echo 'pass'
else
echo '/dev/cdrom /media iso9660 defaults 0 0' >> /etc/fstab
mount -a
fi
yum clean all &> /dev/null
echo 'configure yum is ok'
yum -y install vim &> /dev/null
echo 'vim is ok'
yum -y install net-tools &> /dev/null
echo 'netstat is ok'
yum -y install httpd &> /dev/null
echo 'httpd is ok'
yum -y install bash* &> /dev/null
echo 'bash* is ok'
yum -y install samba &> /dev/null
echo 'samba is ok'
yum -y install mariadb mariadb-server &> /dev/null
echo 'mariadb is ok'
yum -y install policycoreutils-python* &> /dev/null
echo 'semanage is ok'
getenforce
systemctl status firewalld |grep Active
hostnamectl set-hostname maoqiyang
for i in `seq 1 3`;do
echo 'new environment'
done
bash
else
echo 'run failed'
fi
如果复制在了txt里
linux运行时则报错
vim
set ff #查看文件格式
fileformat=dos
set ff=unix #改为unix格式