-1

I am trying to run a command but if the command doesnt succeed in an amount of time (Lets say 30s for example), Cancel out the command and fail out. The script is fairly simple and I am just pausing ntpd and then forcing a time synchronization and starting. However if there is an invalid ntp server this hangs.

systemctl stop ntpd
ntpd -gq
systemctl start ntpd

My thoughts would be, I try to run this in the background, check every 10 seconds to see if the command is still attempting to be run. And say after 3 checks if i see "ntpd -gq" I kill the process and return a failure. Is this the correct way to do this or is there any built in time handling?

user2569803
  • 637
  • 6
  • 11
  • 19
  • 1
    I suggest using the timeout configuration built into systemd. Customize the ntpd.service systemd configuration file with the timeouts and restarts. Let systemd do the work. – Lewis M Sep 24 '18 at 17:43

1 Answers1

1

The shell doesn't have this kind of time handling.

Running the process in the background and checking it periodically as you suggested is the best way to handle this.

dbush
  • 205,898
  • 23
  • 218
  • 273