8298 questions

9759 answers

15542 comments

13863 members

0 votes
15 views 0 comments
by

Hi,
I am using this command to check if NTP is working: ntpclient -h 0.europe.pool.ntp.org -c 1 
I noted that this command returns the result in a row but does not exit and the shell is hanged till press CTRL+C.
Is there a way to make the command exit automatically after the execution? For example, if I would use it in a script.

Thanks,
M

1 Answer

0 votes
by

Hello,

Unfortunately, this command requires CTRL+C to close it and you cant change it.

For example, if you would like to use it in the script you can get creative with it. One example I have found in forums:

# Launch script in background
./my_script_that_includes_command.sh &
# Get its PID
PID=$!
# Wait for 2 seconds
sleep 2
# Kill it
kill $PID

Regards.