【雲巔-Lens】-Shell指令碼示例(Lens客戶端協助配置網路)
大家可以參考使用,對於Linux小白來講可以省不少事,希望對大家有幫助~
Shell指令碼原始碼如下:
#! /bin/bash
## Clear the current screen
clear
echo " "
function highlight_green()
{
echo -ne '\E[1;32;40m'"$1"
echo -e '\E[0m'""
}
function highlight_red()
{
echo -ne '\E[1;31;40m'"$1"
echo -e '\E[0m'""
}
highlight_green "*** Set Network Configuration ***"
## Get Network Configure File Name
filename=$(ls /etc/sysconfig/network-scripts/ | grep ifcfg- | grep -v lo)
#echo "$portname"
## Get Network Port Name
portname=$(ls /etc/sysconfig/network-scripts/ | grep ifcfg- | grep -v lo | cut -d - -f 2)
#echo $portname
## Set Network Type
read -p 'Set Network As(Default is "static")[ dhcp / static ] ' networktype
if [[ "$networktype" == "dhcp" || "$networktype" == "DHCP" ]];then
bootproto=dhcp
else
bootproto=static
fi
## Write General Configure to The File
echo "NM_CONTROLED=yes" > /etc/sysconfig/network-scripts/$filename
echo "DEVICE=$portname" >> /etc/sysconfig/network-scripts/$filename
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/$filename
echo "BOOTPROTO=$bootproto" >> /etc/sysconfig/network-scripts/$filename
## Write Static IP Address to The File
if [[ "$bootproto" != "dhcp" ]];then
read -p 'Please Input IP Address [ xxx.xxx.xxx.xxx ] ' ipaddress
read -p 'Please Input Netmask [ 255.255.255.0 ] ' netmask
read -p 'Please Input Gateway [ xxx.xxx.xxx.xxx ] ' gateway
read -p 'Please Input DNS1 [ xxx.xxx.xxx.xxx ] ' dns1
read -p 'Please Input DNS2 [ xxx.xxx.xxx.xxx ] ' dns2
if [[ $ipaddress == "" ]];then
echo "IPADDR=" >> /etc/sysconfig/network-scripts/$filename
else
echo "IPADDR=$ipaddress" >> /etc/sysconfig/network-scripts/$filename
fi
if [[ $netmask == "" ]];then
echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/$filename
else
echo "NETMASK=$netmask" >> /etc/sysconfig/network-scripts/$filename
fi
if [[ $gateway == "" ]];then
echo "GATEWAY=" >> /etc/sysconfig/network-scripts/$filename
else
echo "GATEWAY=$gateway" >> /etc/sysconfig/network-scripts/$filename
fi
if [[ $dns1 == "" ]];then
echo "DNS1=" >> /etc/sysconfig/network-scripts/$filename
else
echo "DNS1=$dns1" >> /etc/sysconfig/network-scripts/$filename
fi
if [[ $dns2 == "" ]];then
echo "DNS2=" >> /etc/sysconfig/network-scripts/$filename
else
echo "DNS2=$dns2" >> /etc/sysconfig/network-scripts/$filename
fi
fi
## Show Network Configuration
echo ""
highlight_green "*** Show Network Configuration *** "
cat /etc/sysconfig/network-scripts/$filename
echo ""
## Restart Network Service
service NetworkManager restart >> /dev/null 2>&1
sleep 5
read -n 1 -p "Press [ $(highlight_green "1") ] to check network, Other key to cancel…” checkflag
echo ""
if [[ $checkflag == "1" ]];then
echo ""
read -p "Input iConn Server IP Address: " serverip
pingresult=$(ping -c 3 $serverip 2>&1 > /dev/null;echo $?)
if [[ $pingresult == "0" ]];then
echo "Connect to Server $(highlight_green "Successful")!"
else
echo "Connect to Server $(highlight_red "Failed"), Please Check Network Configuration..."
fi
fi
echo ""
read -n 1 -p "Press [ $(highlight_green "Alt + F2") ] to Change to Lens Login UI..."
clear
【使用方法】
1)將以上程式碼儲存為network.sh, 原始檔下載地址:http://pan.baidu.com/s/1o6mT3T4
2)將network.sh檔案複製到/root/目錄下;
3)執行指令碼
#sh network.sh
4)根據提示選擇獲取IP地址的方式,輸入dhcp,或者static,預設static;
5)設定完IP地址後,根據提示輸入需要連線的iConn伺服器地址,測試網路是否連通;
6)如果連通,提示Successful,如失敗,提示Failed;
7)設定完成後提示Alt+F2返回客戶端登入介面。
如下示例:
示例1:
相關文章
- Lens —— 最炫酷的 Kubernetes 桌面客戶端客戶端
- rust druid 之 Lens使用RustUI
- Shell的遠端協助
- 客戶端網路配置上的一點說明客戶端
- 在指令碼中呼叫cassandra客戶端命令指令碼客戶端
- Telegram原始碼之安卓客戶端配置原始碼安卓客戶端
- sch 助shell指令碼加密 02指令碼加密
- gzexe 助shell指令碼加密 01指令碼加密
- Desktop Lens PRO for mac - 螢幕放大鏡Mac
- shell死迴圈指令碼示例指令碼
- 如何配置WSUS客戶端客戶端
- rsync客戶端一鍵安裝rsync指令碼(原始碼)客戶端指令碼原始碼
- ISP演算法:深入聊聊lens shading演算法
- 物理DataGuard客戶端無縫切換--客戶端TAF 配置客戶端
- ClearCase遠端客戶端軟體在網路環境下的配置應用客戶端
- Shell指令碼 – 檢視網路介面資訊指令碼
- 從貼吧看的逆向網路協議過程逆向校園網客戶端協議客戶端
- 【DATAGUARD】物理dg配置客戶端無縫切換 (八.3)--客戶端TAF 配置客戶端
- 分散式配置中心客戶端分散式客戶端
- OutlookAnywhere客戶端配置詳解客戶端
- 客戶端負載均衡配置客戶端負載
- .Net Remoting服務端與客戶端呼叫示例REM服務端客戶端
- Rest Post示例(java服務端、python客戶端)RESTJava服務端Python客戶端
- [指令碼]百度網盤直接下載助手:解決客戶端限制指令碼客戶端
- docker客戶端安裝拉取私有倉庫指令碼Docker客戶端指令碼
- 網路開發基礎客戶端001客戶端
- 21_MQTT協議_客戶端和服務端MQQT協議客戶端服務端
- ICAP: 互換客戶端地址協議客戶端協議
- ntp協議及客戶端開發協議客戶端
- plsql 客戶端亂碼SQL客戶端
- Qt實現網路聊天室(客戶端,服務端)QT客戶端服務端
- 配置安裝版Oracle客戶端Oracle客戶端
- 郵件客戶端的配置使用客戶端
- Swoole 協程 MySQL 客戶端與非同步回撥 MySQL 客戶端的對比MySql客戶端非同步
- python寫的部署windows下zabbix客戶端指令碼薦PythonWindows客戶端指令碼
- 《golang筆記》第四篇-網路客戶端Golang筆記客戶端
- Solaris網路管理:DNS客戶端的設定(轉)DNS客戶端
- hbase - [03] 客戶端常用命令(hbase shell)客戶端