multiple if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple if statement
# 1  
Old 07-06-2010
multiple if statement

Code:
#! /bin/csh
set umr=UMR
foreach  i ( `ls`)
   set file_nm=$i
   set bh_nm=`echo $file_nm | cut -d"_" -f2`
 
      if($bh_nm !=$umr) then
      {
       set bh_ext=`echo $file_nm | cut -d"_" -f4`
       set bh_num_nm="$bh_nm $bh_ext a .txt"
       mv $file_nm  $bh_num_nm
      }
      else
      if ($bh_nm ==$umr) then
      {
         set um_ext=`echo $file_nm | cut -d"_" -f5`
               if ($um_ext=="1.txt") then set um_ext_new=1
               else
               if ($um_ext=="2.txt") then set um_ext_new=2
               endif
         set umr_bh=`echo $file_nm | cut -d"_" -f3`
         set umr_nm= "$umr_bh $um_ext_new b .txt"
         mv $file_nm  $umr_nm
      }
      endif
end



why i always got the error:
Code:
if: Expression syntax error?

Thanks so lot.

Last edited by jdsignature88; 07-06-2010 at 05:07 PM.. Reason: code tags, please...
# 2  
Old 07-06-2010
I'm no expert, but doesn't an 'if' statement usually end with 'fi'?
# 3  
Old 07-06-2010
add an -x to the shebang, you'll easily see what's wrong.
in fact, you need an extra space in
Code:
if ($bh_nm != $umr) then

there.....................^

then you'll have another mistake as csh doesn't seem to know about '{' or '}'
# 4  
Old 01-02-2011
Guys,

I have an issue with if sytax error, tried running using -x option n could not find any errors but when I run the same from cron I am getting Sytax error sometimes.
I used C shell to write below script and when I ran it from CRON it giving me below error
Code:
Your "cron" job on gpsprod3
/archive/SUPPORT/scripts/BUREAU/ALERTS/ALL/processCount/process_count.csh 102
produced the following output:
if: Expression syntax

Any help is much appreciated.


Script:
Code:
#!/bin/csh -x
setenv ENV_NO $1
source /archive/SUPPORT/scripts/BUREAU/ALERTS/SetEnvironment
set HOME=/archive/SUPPORT/scripts/BUREAU/ALERTS/ALL/processCount/$1
set LIST="$HOME/pslist.$$"
set LOG=$HOME/LOG_$$
set USERLOGIN=$HOME/user_login.$$
set mailid=" -r xxx@sample.com"
touch $LIST
if ( $1 == "574C" ) then
/usr/ucb/ps -auegwx | grep \/g574cpd\/appl\/gloss\/G574CLIVE_GLOSS\/GLOSS | grep -v grep | grep -v task | grep -v find | grep -v gsb
tools | grep -v 'wc -l' >> $LIST.$$
cat $LIST.$$ | wc -l >> $LIST
else if ( $1 == "I039" ) then
/usr/ucb/ps -auegwx | grep \/ina039pd\/appl\/ina\/INA039\/GLOSS | grep -v grep | grep -v task | grep -v find | grep -v gsbtools | gr
ep -v 'wc -l' >> $LIST.$$
cat $LIST.$$ | wc -l >> $LIST
else if ( $1 == "039" ) then
/usr/ucb/ps -auegwx | grep \/g$1pd\/appl\/gloss\/G$1LIVE_GLOSS\/GLOSS | grep -v grep | grep -v task | grep -v find | grep -v 'wc -l'
| grep -v gsbtools >> $LIST.$$
cat $LIST.$$ | wc -l >> $LIST
else
/usr/ucb/ps -auegwx | grep \/g$1pd\/appl\/gloss\/G$1LIVE_GLOSS\/GLOSS | grep -v grep | grep -v task | grep -v find | grep -v 'wc -l'
| grep -v gsbtools >> $LIST.$$
cat $LIST.$$ | wc -l >> $LIST
endif
echo "number of processes running through PS command" >>$LOG
cat $LIST>> $LOG
$ISQL -w132 -c -b -S $DSQUERY -U $DB_USER -P $DB_PASW << END_OF_SCRIPT >> $USERLOGIN
use $CONTROL_DB
set nocount on 
SELECT COUNT(1) FROM user_login WHERE user_code LIKE 'b%' AND status='LIVE'
END_OF_SCRIPT
echo "number of processes running through user_login" >>$LOG
cat $USERLOGIN>> $LOG
$ISQL -w132 -c -b -S $DSQUERY -U $DB_USER -P $DB_PASW << END_OF_SCRIPT >> $USERLOGIN.$$
use $CONTROL_DB
set nocount on 
SELECT * FROM user_login WHERE user_code LIKE 'b%' AND status='LIVE'
END_OF_SCRIPT
set proc=`cat $LIST`
set login=`cat $USERLOGIN`
if ( $proc != $login ) then
mailx -s "Processes running differ from user_login entries for $ENV_DESC" $mailid <$LOG
endif


Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples.

Last edited by Franklin52; 01-03-2011 at 04:34 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Multiple FOR;Singe DO statement

Hi guys, I'm trying to send variable commands from 2 different files but I'm not figuring out how to put 2 "i" variables into the command, can anyone help? This is what is done when I read only 1 file: for i in $(file1.txt);do echo "$i " I'm trying to echo 2 variables, matching the lines... (2 Replies)
Discussion started by: demmel
2 Replies

3. Shell Programming and Scripting

Multiple conditions inside my if statement

Hello, I am using shell scripting and I am recieving odd results from my if statement if I want it to enter the loop only if L1 is equal to zero and one of the other criteria are filled, however it is entering at other times as well. What can i do to fix this? i tried seperating it... (6 Replies)
Discussion started by: ryddner
6 Replies

4. Shell Programming and Scripting

Multiple Conditions Perl if Statement

Hello, I'm trying to put together a script that involves pulling data from a config file. I'm attempting to write an if statement to validate one of the pieces of data from the config file, but I think I'm fat fingering it somehow. $config{VALUE} is being pulled from a config file but can only... (4 Replies)
Discussion started by: Picch
4 Replies

5. Shell Programming and Scripting

How to use logical operators in multiple if statement

Hi I want to send a status mail if daily or weekly or monthly batch completed or aborted. Here is the code. if && && || Else if && && || Else if && && || then mailx –s “Status Report” sumone@sumthing.com else print ”try again” Plz suggest the changes. (3 Replies)
Discussion started by: Avi
3 Replies

6. Shell Programming and Scripting

Multiple not statement in AWK

Hi I have a logfile that do grow large rapid, so I like to create a new one with needed info. For some reason the tail -d do not like to redirects its output to a file. tail -f /var/log/daemon.log | grep -vE '(snmpd|ntpd)' gives me real time log of all lines without "snmpd" and "ntpd" This... (4 Replies)
Discussion started by: Jotne
4 Replies

7. UNIX for Dummies Questions & Answers

Initializing multiple variables in one statement

HI, I have 5 variables var1, var2, var3, var4 and var5 I need to initialize all of them to zero. Is there a way to do it in a single line something like this var1=var2=var3=var4=var5=0. I am unable to achieve this. What is going wrong? (2 Replies)
Discussion started by: paku
2 Replies

8. Shell Programming and Scripting

If statement with multiple conditions

I have a script that runs on multiple servers. What I want to do is have the script do the following: if $(hostname) is equal to server or server2 then TO_DIR=go else TO_DIR=stop fi I have tried: if if ] Server is hpux. any ideas? (1 Reply)
Discussion started by: cpolikowsky
1 Replies

9. UNIX for Dummies Questions & Answers

Multiple Condition If statement

Hi, I would like to create an IF statement where if a variable is equal to at least one of 2 (or more) values then the script proceeds. For example: TEST_VAR=2 if ; then echo success! else echo failure fi I understand that the above syntax is wrong but I feel it must be close. Any... (1 Reply)
Discussion started by: msb65
1 Replies

10. UNIX for Dummies Questions & Answers

multiple Logical statement

hi I have following if condition line_by_line="0000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt" if then echo "Exclusion criteria" else echo "Not exclusion criteria" fi above condition works perfectley but if i add one more logical condition... (3 Replies)
Discussion started by: mahabunta
3 Replies
Login or Register to Ask a Question