0

I have a commands like this

time parallel -j 40 :::: filetoprocess.sh
time parallel -j 40 :::: filetoprocess2.sh

I want to run this commands one afterother i.e when time parallel -j 40 :::: filetoprocess.sh finsih then time parallel -j 40 :::: filetoprocess2.sh but here both run parallel
i have write this commands inside shell script file i.e abc.sh and then i run this as nohup sh abc.sh &

here is what m doing
sh creatingcommds.sh 74.9997891 76.1575846 31.6355471 30.6397432 /cats/rallisdata/cropdatazone1/new43REQ 43REQ_20170513 sleep 2 && time parallel -j 40 :::: filetoprocess2.sh && sleep 2 && sh creatingcommds.sh 74.9997891 76.1575846 31.6355471 30.6397432 /cats/rallisdata/cropdatazone1/new43REQ 43REQ_20170523 sleep 2 && time parallel -j 40 :::: filetoprocess3.sh

creatingcommds.sh file creates 80 that is used by time parallel -j 40 :::: filetoprocess2.sh but here i getting file not found error.

  • I think using && in the script will help – George Udosen Jul 6 '17 at 10:35
  • @George can we please give me some example coz m new in shell script world time parallel -j 40 :::: filetoprocess.sh && !! this is what u r saying – Gaurav Singh Jul 6 '17 at 10:36
  • yes sir that is all you need to do – George Udosen Jul 6 '17 at 11:09
  • why the sleeps?? the next command will only run if the previous was successfull. Just remove the sleeps. – Ziazis Jul 6 '17 at 12:33
  • @Ziazis yaa i have checked without sleep but still i get file not found error but i can see file has been created .. – Gaurav Singh Jul 6 '17 at 12:34
0

What you need is the && how George mentioned in the comment already.

&& means the next listed command will be run only if the previous command returned a exit value of 0. You can also use || if you want to run the next command only if the first one failed - or returned a value not being 0.

So for your case it would be:

time parallel -j 40 :::: filetoprocess.sh && time parallel -j 40 :::: filetoprocess2.sh

Which means it will run once the first command is successfully finished and won't run if the first one failed.

Try it out with

echo test 1 `sleep 2` && echo test 2 `sleep 2` && echo test 3 `sleep 2`
  • does it will works for more than two commands – Gaurav Singh Jul 6 '17 at 12:09
  • Yes, after each && it means the leading command must have been completed successfully. You can test it by using something like e.g. look at the edit... – Ziazis Jul 6 '17 at 12:11
  • not working i have added extra information on my question please check ..help me if u can – Gaurav Singh Jul 6 '17 at 12:26

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.