KSH - Issue with endless loop.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH - Issue with endless loop.
# 15  
Old 06-22-2011
zip has a delete option, and a zip mounted to a PC is a directory!
# 16  
Old 06-23-2011
Long shot but I would suggest you eliminate the main and init functions and place the code in these functions directly into the shell script to ensure that declared variables have global scope. Depending on the version of ksh you are using, you can run into variable scoping issues declaring variables within a function and then using that variable in another function.
# 17  
Old 06-23-2011
Often, if variables are first loaded or exported in the ksh main flow, then references to them in functions work, unless the function ends up in a pipe chain and so in a child process, in which case it can set it for its own benefit, but that change does not make it back to the parent.

A great part of learing is learning what works and staying away from wha does not, so life is double hard as a newbie: wrong approach, coded wrong, unstable or unworkable, much longer than necessary, usually not nicely formatted, and for many experts trying to help, not like anything they would write. I have an acronym, OPC, for other people's code or children. One obstacle to reusable code is that it may be cleaner, easier, better to write from scratch and discard. I use cscope (on a web server) so I can find bits of code without looking at all that OPC! Smilie
# 18  
Old 06-24-2011
You mention that this is an hourly job. I assume cron.
There is potential for the script to misbehave if any run takes longer than one hour because the workfile names in /tmp do not have unique names.
May be worth having a simple interlock mechanism (e.g. a "flag" file) to prevent a second instance starting.
# 19  
Old 06-24-2011
Yes, or a simple ps test:
if [ $( ps -fu "$USER" | grep -c "${0##*/}" ) != 2 ]
  ... # report overrun
  exit 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with accidental endless loop

I was practicing writing simple loops as I am a new bash user and I created this script, which turned out to be an endless loop where the echo output does not stop and I do not see where my mistake is. #!/bin/bash echo 'enter a number from 1 to 100' read number while do ... (2 Replies)
Discussion started by: goldenlinx
2 Replies

2. Shell Programming and Scripting

Script runs in endless loop

Hi, AM very new to shell scripting and try to run a simple do while loop statement, but it ends up running endlessly. please can anyone assist, dunno what am doing wrong, any useful suggestions will be welcomed. #!/bin/ksh ### To check a running process instance #################... (5 Replies)
Discussion started by: bayoo
5 Replies

3. Shell Programming and Scripting

[Solved] Endless while loop when compare files

Hi All, I've written a script to read 2 files and compare the contents using while loop but somehow when $line is not found in test2, the script will continue looping. Below is my code, pls advise what could went wrong TIA Nick for line in test1.txt | while read line do grep -i... (4 Replies)
Discussion started by: Nick1971
4 Replies

4. Shell Programming and Scripting

Preventing an endless loop with recursive grep

When finding a string in files within a directory, one can use this: grep -r "searchstring" dir/subdir/ > listofoccurrences.txt For brevity sake one can enter the intended directory and use this: grep -r "searchstring" . > listofoccurrences.txt which as I found out leads to an endless loop,... (2 Replies)
Discussion started by: figaro
2 Replies

5. Shell Programming and Scripting

Help with While loop in KSH

Hi, I want to write a while loop like this can any one say me whats wrong with my loop USAGE="Usage: Mail.ksh" integer i=3 while ((1<i<=3)) do . . . . (( CMD_JUL = LSD_JUL - i )) CUR_MAINT_DATE=$(julian2date ${CMD_JUL}) . . . i=i-1 done (1 Reply)
Discussion started by: bhagya2340
1 Replies

6. Shell Programming and Scripting

[PHP] endless loop mimics a cron. Make sure only one instance is running

Hi, PHP user here. I'm using an endless loop to perform to mimic a cron. The script does something every 20 minutes. It sleep()s in the meantime. I have various checks that ensure that only instance can run, including a "gentleman agreement" locked file. However, I'd like to make sure... (2 Replies)
Discussion started by: jjshell
2 Replies

7. Shell Programming and Scripting

calculating endless columns

I have about 5000 columns of data that i need to convert all of it into pecentages. for shorter colums i have been using this code: {print $1/($1+$2)*100,$2/($1+$2),$3/($3+$4)*100 .....} but this is a teadious process... is there anyway to do it without having to write all of them out? sample... (20 Replies)
Discussion started by: chronicx
20 Replies

8. Shell Programming and Scripting

For loop in ksh..Please help..

Hi ALL, I need to take some command line arguments for my script and then want to run a function for each argument.I thought of using for loop as below, but its not working , can some one please help... #!/bin/ksh lpar1=$1 lpar2=$2 lpar3=$3 lpar4=$4 lpar5=$5 echo "$lpar1" >>lpar.txt echo... (4 Replies)
Discussion started by: prashant43
4 Replies

9. Shell Programming and Scripting

Endless Loop

Hi, I'm pretty new to UNIX shell scripting and need some help. We have an Informatica interface that dumps any files that have errors into a directory. I need to check that directory periodically for any of up to 9 files that might be in it and run a specific process for each file found. The... (3 Replies)
Discussion started by: JeffR
3 Replies

10. Shell Programming and Scripting

Endless loop - Fork function failed?

I need a quick script that will serve as a sort of "real time monitor" for watching some log files. I am using Bourne shell in HP-UX 10.20. I have basically created a script that never ends, unless of course I manually terminate it. Here's the script (it's called qhistory): clear echo "REAL... (3 Replies)
Discussion started by: cdunavent
3 Replies
Login or Register to Ask a Question