Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to write a script and put it in /etc/rc.local so that

if lan is connected then

rfkill block all

else

nmcli con up id 'Network id' --nowait

How should I write the if part and how should I check for "lan is connected" ?

share|improve this question
    
Please don't cross-post. –  Dennis Williamson Feb 25 '11 at 1:07

1 Answer 1

If the LAN is up, then you'll have a default route; otherwise, you shouldn't. So rather than check for particular interfaces, I'd just check for a default route.

I don't have a Linux box to test on, so can't tell what ip(8) gives you, but route(8) has rather poor error exit codes when there's no routes, so instead I'd just rely upon the exit code of grep -- if there's an interface: line, then you have a LAN.

function have_lan() {
  route -n get  default | fgrep -q interface:
}
share|improve this answer
    
Might be even better to try pinging the default route. –  vtest Jul 16 '11 at 9:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.