0

This is a CentOS 6.x box, on it I have two things that I need to run one right after the other - a shell script and a .sql script.

I want to write a shell script that calls the first script, lets it run and then terminates it after a certain number of hours, and then calls the .sql script (they can't run simultaneously).

I'm unsure how to do the middle part, that is terminating the first script after a certain time limit, any suggestions?

bentramer
  • 21
  • 1

1 Answers1

0
script.sh &
sleep 4h && kill $!
script.sql

This will wait 4 hours then kill the first script and run the second. It always waits 4 hours, even if the script exits early.

If you want to move on immediately, that's a little trickier.

script.sh &
pid=$!
sleep 4h && kill "$pid" 2> /dev/null &
wait "$pid"
John Kugelman
  • 349,597
  • 67
  • 533
  • 578