【雲巔-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 指令碼學習指令碼
- Desktop Lens PRO for mac - 螢幕放大鏡Mac
- ISP演算法:深入聊聊lens shading演算法
- rsync客戶端一鍵安裝rsync指令碼(原始碼)客戶端指令碼原始碼
- Shell指令碼 – 檢視網路介面資訊指令碼
- Telegram原始碼之安卓客戶端配置原始碼安卓客戶端
- 如何幫助金融客戶“用好雲”?
- 物理DataGuard客戶端無縫切換--客戶端TAF 配置客戶端
- Lens成為最受歡迎的Kubernetes IDE – thenewstackIDE
- 網路開發基礎客戶端001客戶端
- [指令碼]百度網盤直接下載助手:解決客戶端限制指令碼客戶端
- 從貼吧看的逆向網路協議過程逆向校園網客戶端協議客戶端
- 分散式配置中心客戶端分散式客戶端
- k8s筆記3--Kubernetes IDE LensK8S筆記IDE
- Mac 終端執行 shell 指令碼Mac指令碼
- Qt實現網路聊天室(客戶端,服務端)QT客戶端服務端
- hbase - [03] 客戶端常用命令(hbase shell)客戶端
- 郵件客戶端的配置使用客戶端
- 21_MQTT協議_客戶端和服務端MQQT協議客戶端服務端
- ICAP: 互換客戶端地址協議客戶端協議
- 《golang筆記》第四篇-網路客戶端Golang筆記客戶端
- 客戶端的js js指令碼的引入 js的解析過程客戶端JS指令碼
- Linux shell指令碼判斷伺服器網路是否可以上網Linux指令碼伺服器
- Swoole 協程 MySQL 客戶端與非同步回撥 MySQL 客戶端的對比MySql客戶端非同步
- shell指令碼指令碼
- [ Shell ] 通過 Shell 指令碼匯出 CDL 網表指令碼
- 雲端計算教程學習路線影片原始碼課件:shell指令碼實現獲取圖片原始碼指令碼
- OSSEC服務端配置客戶端批次部署方案服務端客戶端
- Thrift 客戶端-服務端 零XML配置 註解式配置客戶端服務端XML
- Fast Camera Lens Blur:AE/PR鏡頭模糊虛焦外掛AST
- 【工具使用】【Shell指令碼】【gitlab】下拉所有的倉庫程式碼並指定分支推送給客戶倉庫指令碼Gitlab
- MQTT協議從服務端到客戶端詳解MQQT協議服務端客戶端
- shell指令碼案例指令碼
- 常用shell指令碼指令碼
- Linux Shell指令碼Linux指令碼
- 網狐客戶端-win32客戶端Win32