![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script which take a snap shot of Topas | abhishek27 | AIX | 6 | 08-18-2008 08:59 PM |
| Delete all occurence of a word in one shot | namishtiwari | Shell Programming and Scripting | 6 | 08-24-2007 09:41 AM |
| unix screen shot | royal | UNIX for Dummies Questions & Answers | 7 | 07-14-2004 05:36 PM |
| Print Multipul Fiels as One shot | geoquest | UNIX for Dummies Questions & Answers | 9 | 04-10-2002 09:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
My first shot at variables
Okay, so im setting up a script to start my internet dependent scripts once I am connected to the net. It got complicated because of the different networks I frequent but it goes something like this:
Code:
n=1
iwconfig wlan0 > wireless.txt
m= grep -c MGHS /home/jake/Scripts/wireless.txt
o= grep -c NMU /home/jake/Scripts/wireless.txt
while [ $n -le 50 ]; do
echo $n & sleep 3
let n++
if (ping -c 1 www.google.com)
then sh /home/jake/Scripts/netdepsu.sh
elif test "$m" -ne "0"
then sh /home/jake/Scripts/netdepsu.sh
elif test $o -ne $0
then sh /home/jake/Scripts/netdepsu.sh
else echo "no internet"
fi
done
./looper.sh: line 13: test: : integer expression expected ./looper.sh: line 15: test: -ne: unary operator expected if I dont have that space after those '='s up top then I get this error: ./looper.sh: line 6: -c: command not found ./looper.sh: line 7: -c: command not found I know this has to be an easy fix if anyone could let me know I'd be ever so grateful.... |
|
||||
|
I think i figured it out..
it was a problem with assigning the variables... [CODE}#looper n=1 iwconfig wlan0 > wireless.txt grep -c MGHS /home/jake/Scripts/wireless.txt m=$? grep -c NMU /home/jake/Scripts/wireless.txt o=$? while [ $n -le 50 ]; do echo $n & sleep 1 let n++ if (ping -c 1 www.google.com) then sh /home/jake/Scripts/netdepsu.sh elif [ "$m" = 0 ] then sh /home/jake/Scripts/netdepsu.sh & echo "MGH" & break elif test [ "$m" = 0 ] then sh /home/jake/Scripts/netdepsu.sh & echo "NMU" & break else echo "no internet" fi done [/CODE] yay for my most complicated script ever!!! it only took me 7 hours! |
|
||||
|
It's still not correct, the value of $? is 0 for match and 1 for no match after grep -c
The construct you are looking for is backticks. Code:
m=`grep -c MGHS /home/jake/Scripts/wireless.txt` o=`grep -c NMU /home/jake/Scripts/wireless.txt` In other news, the parentheses around the ping in the if are superfluous, and the & you use in a few places means "background this process"; you want "&&" which means "and if the previous command was successful, also run ..." or perhaps just semicolon, which is basically equivalent to newline. |
|
||||
|
Oh, another thing:
Code:
foo=bar echo boink To assign a variable value which contains spaces, you want Code:
foo='bar echo boink' |
|
||||
|
Quote:
Code:
foo="Thanks, I am reading up on quotation examples so I dont have this problem again."; echo $foo |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|