Trouble with Nested Ifs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble with Nested Ifs
# 1  
Old 08-15-2007
Trouble with Nested Ifs

What I thought was going to be very simple has turned out to be really lame, and so I come to you for help.

Code:
mountedon=`df -k /synctest | awk 'NR == 2 {print $1}'`
if [ $mountedon -ne "ids4:/nex02/synctest" ]
then
   # mount /pupcl06
   mountedon=`df -k /synctest | awk 'NR == 2 {print $1}'`
   if [ $mountedon -ne "ids4:/nex02/synctest" ]
   then
      mailx -s "nightly sync FAILED - check drive mountings" name@email.com name2@email.com << EOH
         drive 'synctest' is not mounted properly.
      EOH
      echo mounting error
      break
   else
      echo successfully mounted
      # wmsynctest
   fi
else
   echo was previously mounted
   # wmsynctest
fi
echo yerp

Note: lines are commented out because I don't want this to actually do anything yet.

Basically, I'm trying to check to see if a drive is mounted properly. If it is, execute another script. If not, try to mount it. If that fails, kill the process. If it succeeds, execute another script.

When I run this program, I get an unexpected end of file error. I'm assuming it's related to the nested ifs because of similar errors I read about online.

So if you know how to get around this problem with the ifs, please let me know. Thank you.
# 2  
Old 08-15-2007
The issue is with your Here Document. Remove the indentation before "EOH" and all should be well...

Cheers,
ZB
# 3  
Old 08-15-2007
Wow thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nested ifs

hi I keep getting an error with this nested if statement and am getting the error unexpected end of file, can anyone help me as to why this wont execute? #!/bin/bash #script to check wether the -i -v statements run correctly removeFile () { mv $1 $HOME/deleted }... (3 Replies)
Discussion started by: somersetdan
3 Replies

2. UNIX for Dummies Questions & Answers

How to use nested ifs in unix?

how to use nested ifs in unix (1 Reply)
Discussion started by: pratima.kumari
1 Replies

3. Shell Programming and Scripting

How to use IFS in this scenario?

Given the scenario like this, if at all if have to use IFS on the below given example, how it should be used. IFS=/ eg: /xyz/123/348/file1 I want to use the last slash /file1 . So can anyone, suggest me how to pick the last "/" as a IFS. (4 Replies)
Discussion started by: raghunsi
4 Replies

4. Shell Programming and Scripting

read and IFS

Hi, This is out of curiosity: I wanted to extract year, month and date from a variable, and thought that combining read and IFS would help, but this doesn't work: echo "2010 10 12" | read y m d I could extract the parts of the date when separated by a -, and setting IFS in a subshell: ... (3 Replies)
Discussion started by: raphinou
3 Replies

5. Shell Programming and Scripting

while loop with 3 ifs

im messing up somehwere...and can't seem to clean up the script...for it to work objectives: 1. check for today's file, and sleep 30 secs between retries 2. only allow 5 tries before script should fail. 3. if today's file found, wait 30 seconds for it to process.. code: count=0... (8 Replies)
Discussion started by: sigh2010
8 Replies

6. Shell Programming and Scripting

regarding IFS=

hi i am a learner can some explain "export IFS=$(echo "\n\t\a")" i am not able to understand the functionality please help thanks Satya (1 Reply)
Discussion started by: Satyak
1 Replies

7. Shell Programming and Scripting

Shell nested ifs

Hi can someone tell me whats wrong with the following: #!/bin/sh file1=$1 file2=$2 if then if then echo "File 1 is" $file1 echo "File 2 is" $file2 cp $file1 $file2 echo "Copy complete!" else echo "ERROR: File does not exist!" ... (8 Replies)
Discussion started by: philmetz
8 Replies

8. UNIX for Dummies Questions & Answers

Help on IFS command!

Hi! I am working in korn shell. I want to reset the dimiliter for the set command to "|" but instead of a command prompt return I am getting something as below After issuing the command I am getting this....as if the shell is expecting something else. Can anybody suggest what's the problem. ... (2 Replies)
Discussion started by: udiptya
2 Replies

9. Shell Programming and Scripting

problem with IFS

hi, :) I set IFS=":" But when i try to echo $IFS,i am not getting any thing on the screen escept a blank line. any help pls. cheers RRK (11 Replies)
Discussion started by: ravi raj kumar
11 Replies

10. UNIX for Dummies Questions & Answers

IFS variable

How can I set the value for IFS variable (2 Replies)
Discussion started by: mahabunta
2 Replies
Login or Register to Ask a Question