Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-18-2014, 12:34 AM
|
#1
|
Member
Registered: Apr 2014
Posts: 276
Rep:
|
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-18-2014 at 12:35 AM.
|
|
|
05-18-2014, 02:26 AM
|
#2
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
What is your real overall goal? Explain the forest rather than asking about a tree.
|
|
|
05-18-2014, 07:46 AM
|
#3
|
Member
Registered: Apr 2014
Posts: 276
Original Poster
Rep:
|
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.
|
|
|
05-18-2014, 08:58 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,496
|
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.
|
|
|
05-18-2014, 06:18 PM
|
#5
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
Quote:
Originally Posted by nix84
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 06:24 PM.
|
|
|
05-18-2014, 06:55 PM
|
#6
|
Member
Registered: Apr 2014
Posts: 276
Original Poster
Rep:
|
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.
|
|
|
05-18-2014, 07:13 PM
|
#7
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
Quote:
Originally Posted by nix84
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
|
|
|
All times are GMT -5. The time now is 02:13 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|