![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| About shell script to check well formedness of XML | Kochu77 | Shell Programming and Scripting | 2 | 11-21-2008 02:24 PM |
| script check the users in SHELL ? | anything | Shell Programming and Scripting | 3 | 02-01-2008 11:38 AM |
| Check EOF in shell script | ideazhcy | Shell Programming and Scripting | 8 | 07-20-2007 03:29 PM |
| check my first shell script | gridview | Shell Programming and Scripting | 2 | 05-14-2007 03:34 PM |
| check in unix shell script so that no one is able to run the script manually | adi_bang76 | Shell Programming and Scripting | 1 | 11-16-2006 10:43 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
IP check with shell script
hi guys ..newbie here i would like to create a simple script tat will detect wether the machine has IP or not ...
but it seems that my script doesnt really work it kept rebooting... i set this script during boot so that it will check else it will reboot it a shell script thou... Code:
if [!`hostname -i`] then
echo "System rebooting in 3s";
sleep 3;
reboot;
else
echo "Your Current IP is : `hostname -i`";
echo "Starting System in 3s";
sleep 3;
But this end result was my system end up infinite loops of reboots ... hope someone can help me ... thx. |
|
||||
|
IP Check Shell Script
Yea i get IP via DHCP , well i am using D-Link switches with 24 pc's attached to it so sometimes som pc's doesnt get ip therefore i dun wan the pc to sit idle so at first yes i did thought of making it reboot but after i found the /etc/init.d/network start/stop i am gonna replace that with the reboot command instead so it will stop n start the NIC again untill it gets ip.
of course i did put this script after the NIC is started for the first time by the OS itself but then during the boot my script checks it to ensure it has IP n not jus loopback. coz i wanna ensure the pc is always on the network all the time. there no other script that reboots the pc but the script that is below somehow something is wrong i dunno wat makes it keep restarting the network forever instead of checking whether it already has IP or not : i hv a feeling that my code is wrong somewhr pls help... anyone.. ..Code:
if [!`hostname -i`] then
/etc/init.d/network restart;
else
echo "IP : `hostname -i`";
fi
Last edited by bladez; 02-10-2009 at 01:25 AM.. |
|
||||
|
Solution...
i have found solution to it ... just to share it...
Code:
echo "Checking NIC status... Please Wait.";
host **Your Prefered WWW Address**>/dev/null
if [ $? -eq 0 ];
then
echo "Getting Client IP...";
sleep 3;
echo "Your IP : `ifconfig | gawk '/inet addr/{sub(".*:", "", $2);print $2; exit}'`";
else
echo "Re-initiating NIC...";
/etc/rc.d/init.d/network restart;
echo "Re-checking NIC Status...";
ping;
fi
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|