Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
Bash Script
Not sure if this should be in here, but i couldn't see anywhere else it could go.
I'm trying to write a script that would set the IP address of the network card. It works, however i'm wondering if there is a more efficient way to code this?
What i've got so far seems like a lot of code for what it is doing.
Code bellow:
STRING="Working"
RECEVIED="1 received"
PINGFILE="./ping.txt"
echo $STRING
#Try DHCP
dhclient
#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt
#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 192.168.1.252
ifconfig eth0 up
fi
#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt
#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="192.168.1.252" && ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 192.168.0.252
ifconfig eth0 up
fi
#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt
#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="192.168.0.252" && ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 10.0.0.252
ifconfig eth0 up
fi
#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt
#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="10.0.0.252" && ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 10.0.1.252
ifconfig eth0 up
fi
ping -c 1 www.google.com > /root/Desktop/ping.txt
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="10.0.1.252" && ./Desktop//Start_Stuff.sh && exit
else echo "shite, its no working" &&
exit
Yes i know i have spelt received wrong :p
Any help would be appreciated