Shell script runs fine in Solaris, in Linux hangs at wait command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script runs fine in Solaris, in Linux hangs at wait command
# 1  
Old 10-27-2010
Shell script runs fine in Solaris, in Linux hangs at wait command

HI,

I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging.

here is the core of the script
Code:
CFG_FILE=tab25.cfg
sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" |  while IFS="!" read  a b c
do
#echo "jobs output"
#jobs
#echo "jobs -p  "
#jobs -p
# echo "Before entering parallel process  $$ "
#                jobs  -l
#if [[ `jobs | wc -l` -ne 0 ]] ; then
#               jobs|wc -l
#                ps -ef|grep "`jobs -p`"
#fi
 
wait
done

my CFG_FILE is
Code:
this_is_a_test_ttt! lask;djfl;a ljkasfl; as l;jsladfjasldfj aslk;fjas flj;asf fABCDEFGHIJ KLMNOP ABCDELKJ :LKJSDFLKJSDFKLJDFKDJF  DFKSDHFIUI JSF SIDFJISDFISJDIF  ! lkjasdflkjasf

repeated for 32 times.


if i uncomment the body of while loop , here is the output (that shows what for "wait" is waiting)
Code:
[2] +  Running                 <command unknown>
[1] -  Running                 <command unknown>
jobs -p  
28418

Before entering parallel process 28416
Code:
[2] + 28418      Running                 <command unknown>
       1 
myid   28418 28416  0 14:26 pts/31   00:00:00 egrep -v ^#|^$
myid   28421 28416  0 14:26 pts/31   00:00:00 ps -ef
myid   28422 28416  0 14:26 pts/31   00:00:00 grep 28421?28418

what causes this script wait for a while/grep command in linux whereas in solaris it is fine.

To give further details, i suppose to call a (8) background process, for each of line read from the file. So i introduced a wait command and when all complete i read next line and so on.
Since wait was really waiting for grep and not for spawned child, my script broke.

Othercases when it can run fine in linux

1. fewer lines in config file
2. in one test, i shrink one of row length from 260 to 250, it worked.

i can't predict a consitance condition for this behaviour.

Any help is appreciated in fixing / explaining this behaviour.

thanks
AK

Last edited by Scott; 10-27-2010 at 04:22 PM.. Reason: Please use code tags
# 2  
Old 10-27-2010
I regret that I can't decipher what you are actually trying to acheive, however my bet is that from earlier testing you may have a background task still hanging around and the wait command is watching for all background processes to finish (jobs 1 & 2 running unknown command). Try starting a new session to ensure that is not your problem.


I hope that this helps.

Robin
Blackburn/Liverpool
UK
# 3  
Old 10-27-2010
What shells are you using on Gnu/Linux and on Solaris ?
# 4  
Old 10-28-2010
my apologizes for not using tag . and thanks for tagging.

1.
in both machines, i use ksh my program starts #!/bin/ksh , so it should override any shell is being used.

2. to answer the scenario , Robin's guess is right.
here is what i am doing

Code:
 
 
while read table, server_list
do
 
for server in server_list
do
do_somthing with table and server & # in background
done
wait # wait for all my background jobs to finish. 
echo now i can go and read next line 
 
done

now in my cash, wait started waiting for a zombie (unknown command, evetually a grep , sort) and never come out to read next line.

when i was trying to simplify the problem, i removed inner for loop , so my question looks awkward(stupid?)
technically, when i have while loop and have a wait command it shouldn't wait. ofcourse linux does something in background for while loops

i even used a intermediate file for doing sort and grep output and pass it on to while loop, but wait continue to hang.


again, when i started my config file with few lines, it was working fine in linux too. when i started adding more and more lines, it gave error

at one point, when i reduced row length from 260 char to 250 char , it worked too. but script still can work with line length exceeding more than 250 char when fewer lines were there. so i can't say this is the only scenario problem is exhibited.


could somebody help me to understand this..

thanks
AK
# 5  
Old 10-28-2010
What ksh implementation are you using on Gnu/Linux, the real one or pdksh ?
# 6  
Old 10-28-2010
i don't know if i am using pdksh and realksh (i never heard pdksh earlier)
anyway, here is my output
/bin/ksh --version
version sh (AT&T Labs Research) 1993-12-28 n+

seems to be real?

thx
# 7  
Old 10-28-2010
Yes, that's the real one. What version on the Solaris side ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

2. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

3. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

4. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

5. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

6. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

7. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

8. Shell Programming and Scripting

Script Runs fine but not giving any output

Hi, My script is running with no erros but not giving any output can anyonehelp. #!/bin/ksh . /home/application/bin/application.env OUTFILE=Result.txt PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}` echo "1)To get the book last loaded details " read... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

9. Shell Programming and Scripting

Script runs fine, but not in a cron

Okay, I have the following script that runs fine from a command line as well as an executable .sh file. It just moves any file/folder with movie* in the name to a folder called _Movies. The issue I'm running into is when it's call from a cron. find /mnt/HD_a2/BT/complete -iname "movie.*" -exec... (4 Replies)
Discussion started by: sammyk
4 Replies

10. UNIX for Dummies Questions & Answers

Script runs fine on UNIX Server...Not through MSK Tool kit on Windows Server

I have a .sh script which was running fine on all the UNIX Servers (AIX, SunSolaris). The script requires two mandatory parameters and many optional parameters. Now at a different client place who are on a Windows Server, when I try to execute the script through MKS Toolkit, there are couple of... (5 Replies)
Discussion started by: madhunk
5 Replies
Login or Register to Ask a Question