0
#!/bin/bash
ls -l /bin/bash
ls -l /sbin/bash
ls -l /usr/local/bin/bash
ls -l /usr/bin/bash
ls -l /usr/sbin/bash
ls -l /usr/local/sbin/bash

After running this script I want to stop this script If time is more than 60 seconds. Assume 1st commands execute in 10 and second commands take 50 seconds after that I have to stop the execution of the script.

NicK
  • 27
  • 1
  • 9

1 Answers1

3

Use timeout(1)

timeout 60 ./your_script.sh

Or kill it afterwards:

./your_script.sh & :
sleep 60 && kill $!
iBug
  • 35,554
  • 7
  • 89
  • 134
  • without timeout? – NicK Nov 27 '17 at 10:47
  • @NicK Nope. I don't know anything else. Maybe kill it afterwards. – iBug Nov 27 '17 at 10:53
  • I am not linux expert thats why i am facing this issue... I know the way in first line capture the current time and after executing each command check in if else if it exceeds more than time expected. kill the process.. killing command also in the else section of each commands. – NicK Nov 27 '17 at 10:57