bourne shell timing question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers bourne shell timing question
# 1  
Old 01-28-2004
bourne shell timing question

In one of my scripts I do the following

sort +0 x > y
mv y x

In my script x and y are fully qualified. This works 99% of the time. However once in a while the system comes back and says that is cannot access y in the mv command.

I did some research and I suspect that if I insert a "wait" command inbetween these two lines it will work. Although the wait command is for background processes. Is that what's happening here? Is the sort with a redirect happening in the background?

Thanks, Gill

OS = Solaris
# 2  
Old 01-28-2004
wait can not help. I suspect something external to the script. sort can take a while to run. Plenty of time for someone else to do "rm y".
# 3  
Old 01-29-2004
Sabotage? y is actually /xxxx/xxxxxx/xxxxxx/xxxx/nnnnnnnn.xxx.$$ in length. Would someone be able to delete it while the redirection was happening? While quite a few people happen to know this userid/pswd I find this fairly hard to believe. I'll test that scenario though.
# 4  
Old 01-29-2004
Quote:
Originally posted by gillbates
Sabotage? y is actually /xxxx/xxxxxx/xxxxxx/xxxx/nnnnnnnn.xxx.$$ in length. Would someone be able to delete it while the redirection was happening? While quite a few people happen to know this userid/pswd I find this fairly hard to believe. I'll test that scenario though.
Rather than sabotage, how about a bug? Most of us encounter bugs every week. Maybe it's finally happened to you too.

And the file can be removed during the sort. The file will continue to exist without a name.
# 5  
Old 01-29-2004
I'm very good at producing bugs myself. But this code has run as is for years. The server was moved last weekend but I don't think there were any os changes. By the way, the sabotage line came from a user (ex submariner) that decided his bugs had to be sabotage. But considering that these files contain the processes pid to ensure they don't get overwritten by another instance of the process it would have to be someone jerking my chain if they were getting removed. We have a high priced unix consultant here that told me that sort with the redirection causes a seperate process to occur and the redirection is asyncronous so he thought that the move was happening before the redirection flushed the buffers. He suggested that I could add a sleep 1 or rm x before the move and probably never have the problem again. Gill
# 6  
Old 01-29-2004
Quote:
Originally posted by gillbates
We have a high priced unix consultant here that told me that sort with the redirection causes a seperate process to occur and the redirection is asyncronous so he thought that the move was happening before the redirection flushed the buffers. He suggested that I could add a sleep 1 or rm x before the move and probably never have the problem again. Gill
Redirection as you have done does not cause an extra process.

Redirection is not asyncronous with other elements of your script.

Redirection does not cause any buffers to be flushed.

If anything is in the buffer cache and not yet synced to disk, that is irrelevant. All i/o goes though the buffer cache anyway.

"rm x" to make y spring back into existence? Whoa.... I don't even know what to say about that.

"sleep 1" increases the window between the creation of the file and the time the mv needs it. This is likely to make the problem occur with greater frequency.
# 7  
Old 01-30-2004
Perhaps try: sort -o x x
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies

2. Shell Programming and Scripting

Timing the shell script

I have two shell scripts, one written with xargs for parallel processing (p1) and the other written in old school way (p3) . when I execute them, i get the below values. $ time ./p1 real 0m25.36s user 0m0.32s sys 0m0.80s $ time ./p3 real 0m23.25s user 0m6.20s sys ... (4 Replies)
Discussion started by: luhah
4 Replies

3. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

4. Shell Programming and Scripting

Bourne/C shell help

Exercise Five Write a Bourne shell script which: • Professionalism: plan for this from the start. • Has one command line argument. • If the command line argument is a directory then the script should output the number of files in the directory. • If the command line argument is an ordinary... (2 Replies)
Discussion started by: moesom
2 Replies

5. UNIX for Dummies Questions & Answers

Bourne-sh (not bash) question about nested loops and sed

Here's the input: alpha, numeric or alphanumeric string ("line 1 string") numeric string ("line 2 string") numeric string ("line 3 string") numeric string ("line 4 string") ... where - each numeric string is in a pattern that can be matched with RE but - there can be any number of... (2 Replies)
Discussion started by: uiop44
2 Replies

6. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

7. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

8. Shell Programming and Scripting

Bourne Shell: if elsif question

Hi All, Must be something obvious I am missing, but the simple script below doesn't work. #!/bin/sh x=4 if then echo "x is $x" elsif then echo "x is greater than 4" else echo "x is less than 4" fi When I run this script, I get the error message: 7: Syntax error... (3 Replies)
Discussion started by: leostar_10
3 Replies

9. UNIX for Dummies Questions & Answers

IF THEN ELIF question in BOURNE SHELL

Hi, I get an error when executing this sample script. #!bin/sh if ; then echo "you need to enter the release as the first parameter" elif ; then echo "HI how are you ABC" echo "Hi how are you XYZ" echo " hi how are you all" else echo "using the $1 as input parameter" fi i get... (4 Replies)
Discussion started by: arun_st
4 Replies

10. UNIX for Dummies Questions & Answers

Bourne-again shell

Hi guys !! well i'm still new in learning UNIX , and actually i'm still studying it by myself .. anyway, some people told me the Bourne-again shell is a good version of UNIX to work on , and i tried to download yesterday but i didn't know how to start it ...... the ReadMe file associated with... (3 Replies)
Discussion started by: mrsamer
3 Replies
Login or Register to Ask a Question