Script works but doesn't?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script works but doesn't?
# 1  
Old 06-14-2011
Script works but doesn't?

Hi everyone I'm new here so and I'm just starting to learn a bit of Solaris and I'm working on repairing 10 year old scripts for our system here at work.

When I execute the commands at my prompt everything go's through smooth. I'm using gedit to edit my code because I'm still getting used to the vi editor. I copy the script from my .sh file and paste it into my xterm and it will paste half the script so I go and get the rest of my script then paste it in there was well. Then it gets to my if statements and works great and everything does what its supposed to but if I try to run the entire script by itself without me manually doing it I get a

if: Expression syntax

I'm a little confused wondering why it runs manually but not all in my script? Is there a limit to how big a script can be? This one is has 121 lines.

Any help would be much appreciated.
# 2  
Old 06-14-2011
Quote:
Is there a limit to how big a script can be?
No, it's not your problem.

It's possible your interactive shell and shell running scripts are different. It could be better if you give an example.
# 3  
Old 06-14-2011
Quote:
Originally Posted by yazu
No, it's not your problem.

It's possible your interactive shell and shell running scripts are different. It could be better if you give an example.
Heres my script:

Code:
#!/bin/csh -f
set ANMDIR="/u01/app/scanner"
set REGION=02
set ADDRESS=014
set COMMAND1="//u01//app//scanner/scan//mancom//constelltxa1powerlevel"
set COMMAND2="//u01//app//scanner//scan//mancom//constelltxa2powerlevel"
set COMMAND3="//u01//app//scanner//scan//mancom//constella1freqlevel"
set COMMAND5=148
set COMMAND6=149
set COMMAND7="//u01//app//scanner//scan//mancom//constellrxa1freqlevel"
set RESOURCE1="BALD_MOAB_CONSTELL_02_014:Tx_A1_Pwr_Level"
set RESOURCE2="BALD_MOAB_CONSTELL_02_014:Tx_A2_Pwr_Level"
set RESOURCE3="BALD_MOAB_CONSTELL_02_014:Tx_B1_Pwr_Level"
set RESOURCE4="BALD_MOAB_CONSTELL_02_014:Tx_B2_Pwr_Level"
set RESOURCE5="BALD_MOAB_CONSTELL_02_014:Rx_A1_Pwr_Level"
set RESOURCE6="BALD_MOAB_CONSTELL_02_014:Rx_A2_Pwr_Level"
set RESOURCE7="BALD_MOAB_CONSTELL_02_014:Rx_B1_Pwr_Level"
set RESOURCE8="BALD_MOAB_CONSTELL_02_014:Rx_B2_Pwr_Level"
set RESOURCE9="BALD_MOAB_CONSTELL_02_014:Script_Status"
$ANMDIR/bin/imsend $RESOURCE1 text "Processing"
$ANMDIR/bin/imsend $RESOURCE2 text "Processing"
$ANMDIR/bin/imsend $RESOURCE3 text "Processing"
$ANMDIR/bin/imsend $RESOURCE4 text "Reserved"
$ANMDIR/bin/imsend $RESOURCE5 text "Processing"
$ANMDIR/bin/imsend $RESOURCE6 text "Processing"
$ANMDIR/bin/imsend $RESOURCE7 text "Processing"
$ANMDIR/bin/imsend $RESOURCE8 text "Reserved"
$ANMDIR/bin/imsend $RESOURCE9 text "Updating.."
set RESPONSE1=`$ANMDIR/bin/scancont -region_num $REGION -addr $ADDRESS -file $COMMAND1`
set RESPONSE2=`$ANMDIR/bin/scancont -region_num $REGION -addr $ADDRESS -file $COMMAND2`
set RESPONSE3=`$ANMDIR/bin/scancont -region_num $REGION -addr $ADDRESS -file $COMMAND3`
set RESPONSE5=`$ANMDIR/bin/scancont -region_num $REGION -addr $ADDRESS -cmd $COMMAND5`
set RESPONSE6=`$ANMDIR/bin/scancont -region_num $REGION -addr $ADDRESS -cmd $COMMAND6`
set RESPONSE7=`$ANMDIR/bin/scancont -region_num $REGION -addr $ADDRESS -file $COMMAND7`

set KEY1=`echo $RESPONSE1 | /usr/bin/nawk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' | /usr/bin/nawk '{$1=$1;print}' | /usr/bin/nawk '{sub(/^[ \t]+/, "");print}' | /usr/bin/nawk '{printf "%s%s",s,$0;s=" "}End{print ""}' | /usr/bin/nawk '{print}' `
set VALUE1=`echo $RESPONSE1 | /usr/bin/nawk '{print $17}' `

set KEY2=`echo $RESPONSE2 | /usr/bin/nawk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' | /usr/bin/nawk '{$1=$1;print}' | /usr/bin/nawk '{sub(/^[ \t]+/, "");print}' | /usr/bin/nawk '{printf "%s%s",s,$0;s=" "}End{print ""}' | /usr/bin/nawk '{print}' `
set VALUE2=`echo $RESPONSE2 | /usr/bin/nawk '{print $17}' `

set KEY3=`echo $RESPONSE3 | /usr/bin/nawk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' | /usr/bin/nawk '{$1=$1;print}' | /usr/bin/nawk '{sub(/^[ \t]+/, "");print}' | /usr/bin/nawk '{printf "%s%s",s,$0;s=" "}End{print ""}' | /usr/bin/nawk '{print}' `
set VALUE3=`echo $RESPONSE3 | /usr/bin/nawk '{print $16}' `

set KEY5=`echo $RESPONSE5 | /usr/bin/nawk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' | /usr/bin/nawk '{$1=$1;print}' | /usr/bin/nawk '{sub(/^[ \t]+/, "");print}' | /usr/bin/nawk '{printf "%s%s",s,$0;s=" "}End{print ""}' | /usr/bin/nawk '{print}' `
set VALUE5=`echo $RESPONSE5 | /usr/bin/nawk '{print $18}' `

set KEY6=`echo $RESPONSE6 | /usr/bin/nawk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' | /usr/bin/nawk '{$1=$1;print}' | /usr/bin/nawk '{sub(/^[ \t]+/, "");print}' | /usr/bin/nawk '{printf "%s%s",s,$0;s=" "}End{print ""}' | /usr/bin/nawk '{print}' `
set VALUE6=`echo $RESPONSE6 | /usr/bin/nawk '{print $18}' `

set KEY7=`echo $RESPONSE7 | /usr/bin/nawk '{gsub(/^[ \t]+|[ \t]+$/,"");print}' | /usr/bin/nawk '{$1=$1;print}' | /usr/bin/nawk '{sub(/^[ \t]+/, "");print}' | /usr/bin/nawk '{printf "%s%s",s,$0;s=" "}End{print ""}' | /usr/bin/nawk '{print}' `
set VALUE7=`echo $RESPONSE7 | /usr/bin/nawk '{print $16}' `

if ( $KEY1 = 'Tx' ) 
then 
  $ANMDIR/bin/imsend $RESOURCE1 text "$VALUE1"
else if ( $KEY1 = 'No' ) then 
  $ANMDIR/bin/imsend $RESOURCE1 text "No Response"
else if ( $KEY1 = 'Not' ) then
  $ANMDIR/bin/imsend $RESOURCE1 text "Not Equipped"
else
  $ANMDIR/bin/imsend $RESOURCE1 text "ERROR"
endif

if ( $KEY2 = 'Tx' )
then 
  $ANMDIR/bin/imsend $RESOURCE2 text "$VALUE2"
else if ( $KEY2 = 'No' ) then 
  $ANMDIR/bin/imsend $RESOURCE2 text "No Response"
else if ( $KEY2 = 'Not' ) then
  $ANMDIR/bin/imsend $RESOURCE2 text "Not Equipped"
else
  $ANMDIR/bin/imsend $RESOURCE2 text "ERROR"
endif

if ( $KEY3 = 'Frequency' ) 
then 
  $ANMDIR/bin/imsend $RESOURCE3 text "$VALUE3"
else if ( $KEY3 = 'No' ) then 
  $ANMDIR/bin/imsend $RESOURCE3 text "No Response"
else if ( $KEY3 = 'Not' ) then
  $ANMDIR/bin/imsend $RESOURCE3 text "Not Equipped"
else
  $ANMDIR/bin/imsend $RESOURCE3 text "ERROR"
endif

if ( $KEY5 = 'Rx' ) 
then 
  $ANMDIR/bin/imsend $RESOURCE5 text "$VALUE5"
else if ( $KEY5 = 'No' ) then 
  $ANMDIR/bin/imsend $RESOURCE5 text "No Response"
else if ( $KEY5 = 'Not' ) then
  $ANMDIR/bin/imsend $RESOURCE5 text "Not Equipped"
else
  $ANMDIR/bin/imsend $RESOURCE5 text "ERROR"
endif

if ( $KEY6 = 'Rx' ) 
then 
  $ANMDIR/bin/imsend $RESOURCE6 text "$VALUE6"
else if ( $KEY6 = 'No' ) then 
  $ANMDIR/bin/imsend $RESOURCE6 text "No Response"
else if ( $KEY6 = 'Not' ) then
  $ANMDIR/bin/imsend $RESOURCE6 text "Not Equipped"
else
  $ANMDIR/bin/imsend $RESOURCE6 text "ERROR"
endif

if ( $KEY7 = 'Frequency' ) 
then 
  $ANMDIR/bin/imsend $RESOURCE7 text "$VALUE7"
else if ( $KEY7 = 'No' ) then 
  $ANMDIR/bin/imsend $RESOURCE7 text "No Response"
else if ( $KEY7 = 'Not' ) then
  $ANMDIR/bin/imsend $RESOURCE7 text "Not Equipped"
else
  $ANMDIR/bin/imsend $RESOURCE7 text "ERROR"
endif

$ANMDIR/bin/imsend $RESOURCE9 text "Finished"


Last edited by pludi; 06-15-2011 at 04:23 AM..
# 4  
Old 06-14-2011
Oops. I've never used C shell.

Somebody with C-shell experience can help you. I do not know about debug possibilities in this shell (like set -x in sh).

Just a thought - It seems to me in csh the equality operator is "==", not "=".
Code:
if ( $KEY7 == 'Frequency' )

# 5  
Old 06-14-2011
Quote:
Originally Posted by yazu
Oops. I've never used C shell.

Somebody with C-shell experience can help you. I do not know about debug possibilities in this shell (like set -x in sh).

Just a thought - It seems to me in csh the equality operator is "==", not "=".
Code:
if ( $KEY7 == 'Frequency' )

I tried doing the == as well but thank you for trying to help, I've been racking my brain on this for a while.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

PING to AIX works but TELNET FTP SSH doesn't work

root@PRD /> rsh DR KFAFH_DR: protocol failure due to unexpected closure from server end root@PRD /> telnet DR Trying... Connected to DR. Escape character is '^]'. Connection closed. root@PRD /> ftp DR Connected to KFAFH_DR. 421 Service not available, remote server has closed connection... (2 Replies)
Discussion started by: filosophizer
2 Replies

2. Shell Programming and Scripting

SSh works but sftp doesn't for all users except root

I am sorry if i post in wrong Form. i have AIX server in which ssh works for all users but sftp only works for root user . it is too much important for me to solve this . Your help will be greatly appreciated. (1 Reply)
Discussion started by: khalid khanAIB
1 Replies

3. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

4. Solaris

Drop_caches doesn't work on Solaris but works on RHEL6

Hello Experts, I am performing performance tests on a few mysql select queries. I use the following command to clear the memory disk caches. sync && echo 3 | sudo tee /proc/sys/vm/drop_caches I however see that the above command works on RHEL6 but doesn't work on Solaris 10. I asked... (4 Replies)
Discussion started by: Anirudh Kumar
4 Replies

5. Shell Programming and Scripting

Expect_out(buffer) works but it doesn't get all lines

Hello "expect" experts I am new at Expect. I have searched for a little while how to capture multiple lines with Expect and I am almost succeeded on that but I don't get all the lines of a command's output that the script executes on a server. Here is how my script works in a nutshell - ... (6 Replies)
Discussion started by: capacho6666
6 Replies

6. Red Hat

Samba 3.0.33 (sorta) works, 3.5.4 doesn't

I'm trying to get a RHEL 5.4 base system to authenticate against a W2K8 domain With the stock samba-3.0.33, I can use wbinfo and getent just fine, but I cannot actually authenticate. Googling finally led to a bug that strongly suggests that 3.0.33 cannot and will never be able to ... (1 Reply)
Discussion started by: jnojr
1 Replies

7. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfile This code... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

8. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfileThis code works well in... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

9. Shell Programming and Scripting

Script works but doesn't with cron

Good morning, The script below without the hilited text successfully FTPs the files in question to the other server when it is called from the crontab. I don't want to establish an FTP connection when there are no files so I tried including the hilited lines to only establish an FTP connection... (6 Replies)
Discussion started by: philplasma
6 Replies

10. UNIX for Advanced & Expert Users

"kill -14 pid" doesn't works on all processes !!

If I try to run "kill -14 pid", some processes in my application get terminated , while some keeps running. If SIGALRM signal is sent, they should make an exit. What's the reason any process keeps on running. (1 Reply)
Discussion started by: poojac
1 Replies
Login or Register to Ask a Question