Operating System - Linux
1753964 Members
7529 Online
108811 Solutions
New Discussion

Print the flag UP the exit command ifconfig

 
SOLVED
Go to solution

Print the flag UP the exit command ifconfig

Hi,

I need the check if the interface card the my server is UP or DOWN. I have a script, but i´m not have success. Im using the following command line for get the flag "UP".
ifconfig lan0 | head -1 | awk 'BEGIN { FS = "<" } ; { print $2 }'
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: Print the flag UP the exit command ifconfig

Hi:

# lanscan |awk '/lan0/ {print $4}'

Regards!

...JRF...
Wouter Jagers
Honored Contributor

Re: Print the flag UP the exit command ifconfig

I'm not in front of an HP, but check out (I think) this file:

/net/interfaces/lan/status/lan0

Cheers
Wout
an engineer's aim in a discussion is not to persuade, but to clarify.
Peter Godron
Honored Contributor

Re: Print the flag UP the exit command ifconfig

Hi,
have you tried:
ifconfig lan0 | head -1 | awk -F'[<,]' '{print $2}'

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

So far you have not awarded any points !

Wouter Jagers
Honored Contributor

Re: Print the flag UP the exit command ifconfig

Ignore mine, I was thinking of EMS resources.. 't was an early morning.
*blush*
an engineer's aim in a discussion is not to persuade, but to clarify.
SANTOSH S. MHASKAR
Trusted Contributor

Re: Print the flag UP the exit command ifconfig

Hi,

Try this

$ /usr/sbin/ifconfig lan0|grep lan0|cut -d "<" -f 2|cut -f 1 -d ","



-Santosh
Ralph Grothe
Honored Contributor

Re: Print the flag UP the exit command ifconfig

There are countless ways to parse this,
and several to query the nic's state.
Since you began with awk you could do the
parsing like this e.g.

[[ $(ifconfig lan0|awk -F\< '$2~/UP/{split($2,a,",");print a[1]}') = UP ]] && echo up


Madness, thy name is system administration

Re: Print the flag UP the exit command ifconfig

Thanks a lot of!!

my script is work fine.

Tks.

Claudemir