LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2014, 11:34 PM   #1
nix84
Member
 
Registered: Apr 2014
Posts: 276

Rep: Reputation: Disabled
greping ifconfig getting unusual outcomes


When I use:
ifconfig | grep wlan0 1>/dev/null 2>&1 interactively I get a value of 0 ($?) whether wlan0 is up or down.
Within a script the value is always 1 whether wlan0 is up or down.
Can someone explain this? I think it is in the 1>/dev/null 2>&1 but I don'tknow how nor how running in the two modes causes a different outcom.
How can I tell if wlan0 is up or down in a script without showing the ifconfig to the screen?

Last edited by nix84; 05-17-2014 at 11:35 PM.
 
Old 05-18-2014, 01:26 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
What is your real overall goal? Explain the forest rather than asking about a tree.
 
Old 05-18-2014, 06:46 AM   #3
nix84
Member
 
Registered: Apr 2014
Posts: 276

Original Poster
Rep: Reputation: Disabled
The referenced command appears in a function where I am determining whether wlan0 is up or not, that is the goal.
After much frustration and many echo statements I discovered that this was producing a 1 for $? within the script whether the wlan0 was up or down.
I took the command outside of the script and it reversed the value to 0 for $? whether wlan0 was up or down.
Hence this cannot be used to determine wlan0 state.
I can get it to determine the state of wlan0 ONLY by directing the output of ifconfig to a file and doing grep wlan0 on the file but I wanted to do it with a pipe. Further it should not be consistently 0 or 1 depending on whether it is in the script or not in the piped form. As I said, I think the value of $? is a function of the 1>/dev/null 2>&1 and not the pipe or grep but I don't know or can't recall why that should be.
Hope that helps and maybe U have a suggestion on obtaining a yes/no state of wlan0 by other means that would be less gangly than using a file as I resorted to.
 
Old 05-18-2014, 07:58 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
would be nice to show us exactly what have you tried and what went wrong. it should do the same thing inside any script and/or function. The redirection will not affect the return code at all.
 
Old 05-18-2014, 05:18 PM   #5
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by nix84 View Post
Hope that helps and maybe U have a suggestion on obtaining a yes/no state of wlan0 by other means that would be less gangly than using a file as I resorted to.
Use /proc/net/wireless.

As pan64 recommends it is more useful to see your code samples and give you compelling relevant advice to your problem at hand. You still haven't explained "The forest". Determining the wireless interface state by itself is a useless task. So you're obviously trying to solve a bigger problem with determining the wireless interface state as a task. You should explain what you're trying to do because you could be giving yourself and members of this forum the run around without asking the right questions the first time based on your understanding.

Last edited by sag47; 05-18-2014 at 05:24 PM.
 
Old 05-18-2014, 05:55 PM   #6
nix84
Member
 
Registered: Apr 2014
Posts: 276

Original Poster
Rep: Reputation: Disabled
I have given the example string and its outcomes in two conditions and asked if any one had and explanation. I do not see that listing the code will accomplish anything believe me when I say that.
Since no one has even addressed the possible solution I offered I see no need to further this query and am closing this post.
 
Old 05-18-2014, 06:13 PM   #7
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by nix84 View Post
I have given the example string and its outcomes in two conditions and asked if any one had and explanation. I do not see that listing the code will accomplish anything believe me when I say that.
Since no one has even addressed the possible solution I offered I see no need to further this query and am closing this post.
I have addressed your request directly and gave you an answer in which you can follow up and use in my last post. Since you don't appear to be interested in reading or receiving support then I guess there's not much else I can say. RTFM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: OpenStack Summit highlights amazing open source outcomes LXer Syndicated Linux News 0 04-27-2013 02:54 AM
greping services mosheur Linux - Newbie 2 05-03-2012 06:58 PM
conditional greping ut0ugh1 Programming 7 10-27-2011 02:12 PM
greping sendmail tekmann33 Linux - Server 1 09-13-2007 03:23 PM
LXer: Standards Wars: Situations, Strategies and Outcomes LXer Syndicated Linux News 0 03-30-2006 11:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration