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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting In Shell Script Does Second Command Wait For First Command To Complete
# 1  
Old 07-24-2013
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:

Code:
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

The first command is operating on large number of data like 20k. Will it be possible that the second command is executed and rename the temporary file to original file name before the first operation is completed.

Thanks
Angshuman
# 2  
Old 07-24-2013
until a process is complete the following process does not start, unless you run the process in the background, regardless of the running time.
# 3  
Old 07-24-2013
Hi,

Thank you for your reply. This was also my understanding. I am not running the first process in background. However, I get the error intermittently that file does not exist. Hence, I wanted to confirm.

Thanks once again for your confirmation.

Angshuman
# 4  
Old 07-24-2013
Quote:
Originally Posted by angshuman
Hi,

Thank you for your reply. This was also my understanding. I am not running the first process in background. However, I get the error intermittently that file does not exist. Hence, I wanted to confirm.

Thanks once again for your confirmation.

Angshuman
The error will occur when your command to create that file wont find any patterns which you are searching in the file thus no tempfile gets generated.

add below block to avoid it

Code:
 
if [ -f $TEMPFILE ] ; then
mv $TEMPFILE $ORIGFILE
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

2. Shell Programming and Scripting

Bash script parallel tasks and command to wait untill complete?

Hello, im having bash script with while *** command1 && command2 && command3 && done i want to ask how i can prevent overloading server, by waiting untill all commands complete? any low resources intensive command like "wait" - i dont know if exist? (2 Replies)
Discussion started by: postcd
2 Replies

3. Shell Programming and Scripting

Wait for one processes to complete in a shell script

Let's say I start process A.sh, then start process B.sh. I call both of them in my C.sh How can I make sure that B starts its execution only after A.sh finishes. I have to do this in loop.Execution time of A.sh may vary everytime. It is a parameterized script. (17 Replies)
Discussion started by: rafa_fed2
17 Replies

4. Shell Programming and Scripting

Korn shell. wait command and crontab

I have the following ksh script: sqlplus usr1/pw1@DB1 @$DIR/a.sql $1 & sqlplus usr2/pw2@DB2 @$DIR/b.sql $1 & wait echo "Done!" Where $DIR is a variable with the absolute path where a.sql and b.sql are. For some time, I've been running this script daily and it works fine. The intentions is... (5 Replies)
Discussion started by: acarpio89
5 Replies

5. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

6. Solaris

Show complete command on command line when we use 'ps'

Hi, When I query using ps -ef, the complete command is not displayed and is truncated. Can you please tell me a method to resolve this ? I have tried the below. ps -ef | cat ps -ef | grep imp >/tmp/t1.txt /usr/ucb/ps -auxw pargs <pid> /usr/ucb/ps -aefyl | grep imp Thanks (11 Replies)
Discussion started by: mk1216
11 Replies

7. Shell Programming and Scripting

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 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... (13 Replies)
Discussion started by: aksaravanan
13 Replies

8. UNIX for Dummies Questions & Answers

How do you wait for command substitution processes to complete?

When running a command using the >(cmd) syntax in bash how do you wait for the command to complete before moving on in your script? Here is a simple example: zcat largefile.gz | tee >(wc && echo “HELLO”) > /dev/null # I tried wait, here but it doesn't wait for the process in the subshell.... (8 Replies)
Discussion started by: mrvwman
8 Replies

9. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

10. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies
Login or Register to Ask a Question