Simple While Loop not exitting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Simple While Loop not exitting
# 1  
Old 09-08-2011
Simple While Loop not exitting

Hi Experts,

Im running a bit complicated sql script and for reasons of scheduling,I wrapped it around in a simple shell script. So, when I run it, it do creates an output file and writes to it everytime I run it & this is what exactly I wanted.
However, it is not exiting the while loop no matter what I do. Here is what I have in my sql script.

HTML Code:
#!/bin/ksh

A=1
while [ $A -lt 3 ];
do

echo 'Process Start'

sqlplus -s UID/PWD@DB @/Users/PGonzales/File.sql >>/Users/PGonzales/Filelog.log

echo "Writing to log file"

echo 'Process End'

A=`expr $A + 1`
done
exit
No matter what I do, it is not exitting the while loop and I have to ctrl^D to exit out. I tried my luck with if loop as well and even there, it is not exiting.

Please help
regards,
PGonzales.
# 2  
Old 09-08-2011
Are you sure you have expr on that machine ?

Can you try this inside loop to increment
Code:
A=$(( $A + 1 ))

Also, put #!/bin/ksh -x and observe the output when you run the script.

Regards
Peasant.
This User Gave Thanks to Peasant For This Post:
# 3  
Old 09-08-2011
Peasant,

You are so correct. I did which on the expr and it did not show anything under there. Thanks a bunch.

Appreciate your help and I cant believe that I was doing such a silly mistake.

This forum is truly a blessing for a novice like me.

regards,
PGonzales.
# 4  
Old 09-08-2011
Odd in several ways.

expr has been around a long time and is part of POSIX. It seems to me unlikely that a system would not have it. Is there a UNIX platform out there in common use that does not provide expr?

If expr were indeed missing, the shell should have provided an error message (although perhaps stderr was redirected).

Finally, if there was indeed an infinite loop, control-d would not stop it. That merely sends EOF. control-c would be necessary to send a signal to terminate the foreground process group. control-d would only have an effect if something is hanging while waiting on input.

Regards,
Alister
# 5  
Old 09-08-2011
echo $PATH and uname -a would be illuminating.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Dont Allow Exitting from a Script

Hello, I wrote a script and disabled Ctrl+C using trap ' ' 2 For security, I cannot allow users to exit the script on their own for then they would have access to the command prompt. Are there any other cases that I need to cover? Thank you. I'm new to scripting. (6 Replies)
Discussion started by: fzivkovi
6 Replies

2. Shell Programming and Scripting

Simple loop using for

Dear experts, I am writing a bash script. At some point of the program I need to have 'for' loop. For simplicity I tried with some other simple code. The format of the loop is given below. k=51 m=55 for j in {$k..$m};do w=$(($j+2)) z=$(($j+9)) echo "$w, $z" done But my... (4 Replies)
Discussion started by: vjramana
4 Replies

3. Shell Programming and Scripting

a simple loop

Does any body can help me with a loop in this example? if then if then runner=$(grep "$1" "$2") runne=$(grep "$1" "$3") run=$(grep "$1" "$4") fi fi # # Message on screen... (3 Replies)
Discussion started by: bartsimpsong
3 Replies

4. Shell Programming and Scripting

Simple while-loop problem

Maybe because its Friday, but I can't get a simple while loop to work! #!bin/bash i=0 while do echo "Hello" ((i++)) done (17 Replies)
Discussion started by: linuxkid
17 Replies

5. UNIX for Dummies Questions & Answers

Simple loop

I need to chmod a bunch of files with a specific extension in one directory. If I understand correctly first I would run ls command like this ls -R | grep .mp3 > /tmp/list once I have the output file I should be able to run a loop to chmod all the files in the list created. This is where... (5 Replies)
Discussion started by: eugenes18t
5 Replies

6. Shell Programming and Scripting

Simple using For loop

Hi expert, I'm using csh Code: #!/bin/csh set x = 0 set number = `awk '{array=$0} END {print array;}'` i want to use for loop to store data to $number repeatly untill x = 23 How to use c shell for loop? (2 Replies)
Discussion started by: vincyoxy
2 Replies

7. Shell Programming and Scripting

A simple (?) loop

I have what I believe is a simple programming question. I have a text file that looks like: mol 1 G:\stereo01.hin block text ... ... ... endmol 1 However, I would like a file that repeats this entire block of text several times over. The lines of text in the middle remain the same for each... (2 Replies)
Discussion started by: red baron
2 Replies

8. Shell Programming and Scripting

simple while loop

i have a script called file2 #!/bin/ksh i=0 while do echo $i >> result.txt i=`expr $i + 1` done echo "***********************" >> result ------------------------------------------------------------------- (10 Replies)
Discussion started by: ali560045
10 Replies

9. Shell Programming and Scripting

simple for loop

i have the following process running in background: when i give "ps -lef" ------------------------------------------------------------------------ user2 user1 user1 user3 user1 user4 user5 user4 user3 user4 user2 user1 user1 user3 user1 user4 (3 Replies)
Discussion started by: ali560045
3 Replies

10. Shell Programming and Scripting

a simple while loop

Hallo everyone I might just be being dumb, but I am using the BASH shell and cannot get the following script to work: x=0 while do echo $x x=´echo "$x + 1" | bc´ done Can anybody help me out. I am just get a repeating output saying: bc: command not found 0 + 1: command not... (5 Replies)
Discussion started by: syno
5 Replies
Login or Register to Ask a Question