I execute a script that splits a big file into little files. Immediately afterwards I ask if (-f *filename) then ....

Sometimes the script doesn't finish so the if doesn't work. I tried sleep but that doesn't solve the problem.

My script: split -l $number_lines - file2 < file1 >& /dev/null &

How should i use 'wait'?

Thank you!

  • 3
    Can you please include your script (or at least the relevant parts) in your question by updating it (use [edit] below the question – Anthon Oct 2 '14 at 13:09
  • wait doesn't work? I don't know csh syntax but you should use a while (not files) { sleep 1 } logic. – Alex Oct 2 '14 at 18:31

There are a few methods to crack your issue wide open.

I am understanding that you are using a C-Shell (I use Bash, but certain environment I interact with use the TCSH.).

One method to accomplish your requirement is systemic process-oriented locking.

The Process Locking approach looks most like this:

set process_id = $1
set sub_sequent_cmd = $2
while (pidof $ANTECEDENT_PROC)
  sleep 10
  if (pidof $ANTECEDENT_PROC)
    sleep .1

The premise of the solution is what's important. Monitor the proc with an external script, and when the antecedent proc ends, execute your subsequent script.

This would only work if you refactor your csh script to be invoked in an exported csh session.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.