what's wrong with my bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting what's wrong with my bash script?
# 1  
Old 02-19-2008
what's wrong with my bash script?

hi,

please point out what's wrong with my script. im feeding it a list containing fqdn, sit should ssh into each and verify that atleast one of its virtual backup ip resolves into one of its virtual hostnames .. anyway the objective shows in the script... however, im having problems in the
innermost if condition.. "else" wont get executed.

Code:
#!/bin/bash -x

for i in `cat $1`
do
        _HOSTNAME=`echo $i |cut -d"." -f1`
        /usr/bin/ssh $i "
                echo $_HOSTNAME;
                for i in `/sbin/ifconfig -a | grep 172\.39 | awk '{print $2}'`
                do
                        if [[ -n `nslookup $i | grep $_HOSTNAME | awk '{print $2}'` ]]
                        then echo "backup interface OK"
                        else echo "backup interface NOT OK"
                        fi
                done
        " >> $1.out 2>/dev/null
done

TIA!
# 2  
Old 02-21-2008
aww man... no replies until now? Smilie
# 3  
Old 02-21-2008
in both for loop, you are using same index "i".
So in the if condition, second "i" will be used, Is this the one you want ?
# 4  
Old 02-21-2008
changing the variable to another ('j' for example) hangs at this point:

++ awk '{print $2}'

yes the variable is a problem, but i think there's something else with the way i did it.

please suggest.
# 5  
Old 02-22-2008
could you please post the latest code and the debug o/p ?
Please state your current issue as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

What's wrong with my bash code?

I want to let sleep 3 in the background and echo $i pkglists="a b c d e f g" f() { local i set -- $pkglists && ((i +=2)) && sleep 3 &;echo $i } f (3 Replies)
Discussion started by: yanglei_fage
3 Replies

3. Shell Programming and Scripting

What's wrong with the following script

# Log directory and file LOGDIR=. LOGFILE=$LOGDIR/wgetlog-`date +%m-%d-%y-%H:%M`.log ...... $WGET --user-agent="Mozilla/5.0" --secure-protocol=auto --post-data $AUTH_DATA --save-cookies=$COOKIE_FILE --keep-session-cookies $SSO_SERVER$SSO_AUTH_URL -O sso.out >> $LOGFILE 2>&1 ........ ... (2 Replies)
Discussion started by: jediwannabe
2 Replies

4. Shell Programming and Scripting

Bash conditional | getting logic wrong?

I have a file cat <<EOF > /tmp/test Line one Line two Line three EOF Now I am trying to get the exit stat ($?) of 1 if any text is found and 0 if any text is not found using grep, i.e. just reversing the exit status of grep # (snippet 1) this one is not working!!! retval $?... (4 Replies)
Discussion started by: the_gripmaster
4 Replies

5. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

6. Shell Programming and Scripting

Can anyone tell me what's wrong with my script

Hi... I am fed up in file handing with array for comparing.... 1st I want save first 2 columns of file 1 I tried like this,, {getline< "file1";ln=$1; lt=$2}then I read second file's 1st and 2nd column..and saved like this and small calculation and initialization var1 =$1 var2 =$2... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies

7. Shell Programming and Scripting

What is wrong with this script

Good day all I have a UNIX script that I created to set a couple of environment variables for my Oracle installation. When I initially run the script, I get the correct values on the inbuilt echo command but when the script completes and I issue an echo statement echo $ORACLE_SID, the... (9 Replies)
Discussion started by: tt1611
9 Replies

8. Shell Programming and Scripting

ps script - What is wrong with it please?

Hi All, I am trying to do a script that prompts the user for the PID and it displays information about that process, this is what I have, but is not working: echo "Please enter your PID:" read pid case $pid in ps | grep $pid esac done * I also needed that this... (1 Reply)
Discussion started by: linuxrose
1 Replies

9. Shell Programming and Scripting

Please help to fingure out what wrong with my tomcat restarting bash script

Hi, I am a nbee to Unix, I have used following script to check my tomcat is running or not and restart if it down. but actually it restart my tomcat each time running even my tomcat still running fine: Script that can run a check and perform an action if the check fails ... (1 Reply)
Discussion started by: quyennd
1 Replies

10. Shell Programming and Scripting

Bash passes flags to shell wrong

Hi, first post, so hello to all. I have a Bash scripting problem that is driving me a bit nutty. It involves a program called 'convert' which is part of the ImageMagick collection. Normal usage from the commandline is: $ convert -resize 120x120 inputfile.jpg outputfile.jpg This is... (7 Replies)
Discussion started by: andyj
7 Replies
Login or Register to Ask a Question