Skip to content

Instantly share code, notes, and snippets.

@ZeroDeth
Created June 27, 2017 16:36
Show Gist options
  • Save ZeroDeth/4c5a1f3e8262ede73fab53de2f3b18d0 to your computer and use it in GitHub Desktop.
Save ZeroDeth/4c5a1f3e8262ede73fab53de2f3b18d0 to your computer and use it in GitHub Desktop.
Checks and ensures that the ntpd service is started and running, and sets it to start at system boot.
#!/bin/bash
# Check if ntp is installed, and, if not, install it.
if ! rpm -qa | grep -qw ntp; then
yum install -y ntp
fi
# Start ntpd if it's not already running.
if ps aux | grep -v grep | grep "[n]tpd" > /dev/null
then
echo "ntpd is running." > /dev/null
else
systemctl start ntpd.service > /dev/null
echo "Started ntpd."
fi
# Make sure ntpd is enabled on system startup.
systemctl enable ntpd.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment