Menu Console
Edit /home/admin/.profile by put the script menu4.sh in this file
/home/admin/menu4.sh
check valid script "./checkIP.sh 192.168.8.9/24"
#!/bin/bash # Test an IP address for validity: # Usage: # valid_ip IP_ADDRESS # if [[ $? -eq 0 ]]; then echo good; else echo bad; fi # OR # if valid_ip IP_ADDRESS; then echo good; else echo bad; fi # function valid_ip() { local ip=$1 local stat=1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS IFS='.' ip=($ip) IFS=$OIFS [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] stat=$? fi return $stat } # set static LAN IP in /etc/network/interfaces IP_ADDR=$1 IP_ADDR_NET=${IP_ADDR/\//\\/} IP_ONLY=$(sed "s/\/.*//" <<< "$IP_ADDR") echo $IP_ONLY if valid_ip $IP_ONLY; then stat=true; else stat=false; fi if [ "$stat" = true ] ; then echo "IP set" sudo /bin/sed -i "s/address.*/address $IP_ADDR_NET/g" /etc/network/interfaces else echo "IP not valid" fi
check valid GW ip "./checkGW.sh 192.168.0.1"
#!/bin/bash # Test an IP address for validity: # Usage: # valid_ip IP_ADDRESS # if [[ $? -eq 0 ]]; then echo good; else echo bad; fi # OR # if valid_ip IP_ADDRESS; then echo good; else echo bad; fi # function valid_ip() { local ip=$1 local stat=1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS IFS='.' ip=($ip) IFS=$OIFS [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] stat=$? fi return $stat } # set static LAN IP in /etc/network/interfaces GW_ADDR=$1 if valid_ip $GW_ADDR; then stat=true; else stat=false; fi if [ "$stat" = true ] ; then echo "GW set" sudo /bin/sed -i "s/gateway.*/gateway $GW_ADDR/g" /etc/network/interfaces else echo "GW not valid" fi
Last modified 3 years ago
Last modified on 03/22/22 09:26:48
Attachments (1)
- menu4.sh (2.8 KB) - added by 3 years ago.
Download all attachments as: .zip