0

I am trying to run a script which takes input from text file and based on the number of entries in it, a command is executed as many number of times. Below is an overview:

cat /tmp/file.txt | while read name
do
<<execute a command using value of $name>>
done

What is happening is sometimes the command executed for particular $name is getting hung due to known issues. Therefore I need in such cases that the command on every value of $name runs only for X number of seconds and if it is not able to complete within that stipulated time, terminate the process and increment loop counter. I was able to make use of sleep and kill but it is terminated the entire loop. I want the next values to be processed in case command gets hung on a row/value. Please advise.

lurker
  • 55,215
  • 8
  • 64
  • 98
Prax
  • 47
  • 1
  • 5

1 Answers1

0

Sounds like you might want something like timeout.

timeout 4 <command>
BHC
  • 690
  • 1
  • 5
  • 16