Imam Abdul Mahmudi
Imam Abdul Mahmudi

Reputation: 303

Set timeout shell script

I want set timeout in my shell script, this is my code:

 /etc/init.d/ntp stop
until ping -nq -c3 8.8.8.8; do
   echo "Waiting for network..."
done
ntpdate -s time.nist.gov
/etc/init.d/ntp start

I want set time out 30 seconds, if more than 30 seconds I want kill that process and change to this process:

hwclock -s

Thankyou

Upvotes: 0

Views: 1201

Answers (1)

jayant
jayant

Reputation: 2389

In bash you can use timeout.

timeout 30s script.sh
hwclock -s

Upvotes: 2

Related Questions