Hi all,

I am trying to write a shell script that submit a couple of jobs .Then in the "job.e.." files looks for the "Finished with all tasks." string and if it exits it continues to lets say step 3 submitting job3 and if not to step 4 and submitting job4. Using commands "qsub job3" and "qsub sub4" respectively. Here is my first trial:

for ((  i = 1 ;  i <= 2;  i++  ))
do
find . -name "job_$i.e*" -exec grep "Finished with all tasks." '{}' \; -print
done

But the above command just prints weather the string exists or not and I don't know how I can proceed from here. I really appreciate any suggestion.


Do you know where the files, job_1.e and job_2.e, are? If so, why use find?

for file in job_*.e   ## adjust path if necessary
do
  if grep -q "Finished with all tasks." "$file"
  then
     : line found; do something
  else
     : line not found; do something else
  fi
done

Otherwise pipe the output of find to a script:

n=0
max=2

while [ $(( n += 1 )) -le $max ]
do
  find . -name "job_$i.e*" |
   while IFS= read -r file
   do
     if grep -q "Finished with all tasks." "$file"
     then
        : line found; do something
     else
        : line not found; do something else
     fi
   done
done
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.