LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2011, 05:29 AM   #1
Flowsen
LQ Newbie
 
Registered: Sep 2011
Posts: 29

Rep: Reputation: Disabled
[solved] ifconfig without output when used in shellscript during startup


Hello,

i have a shellscript, let it call "returnip.sh"
Inside this script, various IP adresses are stored into variables:

Code:
                ETH0=`/sbin/ifconfig eth0 2> /dev/null | egrep -o ". inet Adresse:[0-9]+.?[0-9]+.?[0-9]+.?[0-9]+." | cut -d: -f2 2> /dev/null`
                WLAN0=`/sbin/ifconfig wlan0 2> /dev/null | egrep -o ". inet Adresse:[0-9]+.?[0-9]+.?[0-9]+.?[0-9]+." | cut -d: -f2 2> /dev/null`
                TUN0=`/sbin/ifconfig tun0 2> /dev/null | egrep -o ". inet Adresse:[0-9]+.?[0-9]+.?[0-9]+.?[0-9]+." | cut -d: -f2 2> /dev/null`
                PPP0=`/sbin/ifconfig ppp0 2> /dev/null | egrep -o ". inet Adresse:[0-9]+.?[0-9]+.?[0-9]+.?[0-9]+." | cut -d: -f2 2> /dev/null`
This works fine as long as i run the script from shell. If I start the script using runlevel during startup the script runs but the variables are empty.
All interaces are up at this time so there must be another reason why /sbin/ifconfig returs no value. Could someone please help me?

Thank you.

Last edited by Flowsen; 11-25-2011 at 07:41 AM.
 
Old 11-25-2011, 06:15 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Is at startup only a limited shell available? (I mean ash, dash, nash, etc, etc and not BaSH.)
Does the script run with root rights?
What shows if you run the script but only save the output to a file for troubleshooting purposes? Is it still empty?
BTW why run ifconfig four times when you can output to a temporary file once and grep that four times?
 
Old 11-25-2011, 06:38 AM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Quote:
Originally Posted by unSpawn View Post
BTW why run ifconfig four times when you can output to a temporary file once and grep that four times?
Eh, I agree that the script needs work, but that doesn't sound much better. Surely some Bash 4.0 or Awk magic to do it one fell swoop?
 
Old 11-25-2011, 06:44 AM   #4
Flowsen
LQ Newbie
 
Registered: Sep 2011
Posts: 29

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.
Yes indeed, this could be shortend to execute ifconfig just one time...

Quote:
Is at startup only a limited shell available? (I mean ash, dash, nash, etc, etc and not BaSH.)
Well I think bash is availible because the scripts is running in the background and acting as it should. It checks incomming SMS from a huawei UMTS stick.
Once it gets the SMS, it checks for command, executes and sends back a sms. Everything is working fine except the output varibles ETH0, WLAN0... are empty. It is running as root because reboot command per SMS etc. work fine.


BTW
Code:
                FILES=`ls -A /home/inbox/*${SMSNUMMER}* 2> /dev/null`
this part of the script works just fine

Code:
                ETH0=`/sbin/ifconfig`
still stays empty

Last edited by Flowsen; 11-25-2011 at 07:12 AM.
 
Old 11-25-2011, 07:45 AM   #5
Flowsen
LQ Newbie
 
Registered: Sep 2011
Posts: 29

Original Poster
Rep: Reputation: Disabled
I solved the problem:
Code:
                if [ $ETH0 ]; then
                        STATUS="LAN:$ETH0\n"
                fi
After changing this if case it works now, Just wondering why it worked running the script from shell......
 
Old 11-27-2011, 05:57 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Flowsen View Post
it works now
...because now it only checks exit value. You could have written '/bin/false || STATUS="LAN:$ETH0\n";' and it would equally be of no value ;-p
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ifconfig output explain aamerjavaid Linux - Networking 5 10-28-2011 08:12 AM
What does this ifconfig output mean? rylan76 Linux - Newbie 2 05-15-2009 06:13 AM
[ask] ifconfig output reverse demhyt Linux - Networking 4 09-21-2008 07:06 PM
Output of the ifconfig command isra Linux - General 8 03-20-2007 11:13 AM
ifconfig output alaios Linux - Networking 8 12-02-2004 02:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:13 AM.

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