0

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
1

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:

#!/bin/csh
set process_id = $1
set sub_sequent_cmd = $2
set ANTECEDENT_PROC = XXYYZZ
#
while (pidof $ANTECEDENT_PROC)
do
  sleep 10
  if (pidof $ANTECEDENT_PROC)
  then
    sleep .1
  else
    ./sub_sequent_command
    break
  fi
end

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.

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.