Bash scripts to deploy and verify an NTP server configuration on Ubuntu.
- Installs the NTP server package
- Removes default NTP server entries from
ntp.conf(e.g.0.ubuntu.pool.ntp.org) - Configures
ua.pool.ntp.orgas the sole NTP server - Restarts the NTP service
- Registers
ntp_verify.shto run once per minute via cron
- Checks whether the NTP process is running; starts it if not
- Checks
ntp.conffor unauthorized changes:- Outputs the diff to stdout if changes are detected
- Restores
ntp.confto its deployed state (ua.pool.ntp.orgonly) - Restarts the NTP service
- Both scripts must be uploaded to a GitHub repository named
task4_2. - The repository must contain exactly two files:
ntp_deploy.shandntp_verify.sh. ntp_verify.shmay be run multiple times during task verification.
This section describes how to spin up a local Ubuntu 16.04 environment that matches the grader's setup so you can verify the solution before submission.
Prerequisites: Docker Desktop installed and running.
# 1. Pull the Ubuntu 16.04 image
docker pull ubuntu:16.04
# 2. Start a privileged container (required for the 'service' command)
docker run -it --privileged --name ntp-test ubuntu:16.04 /bin/bashInside the container:
# 3. Install prerequisites
apt-get update && apt-get install -y git cron
# 4. Clone the repository (replace with your actual URL)
git clone https://github.com/<your-username>/task4_2 /root/task4_2
cd /root/task4_2
# 5. Run the deploy script
bash ntp_deploy.sh
# 6. Verify NTP config — should produce no output (no changes)
bash ntp_verify.sh
# 7. Simulate a config change, then verify again
sed -i 's/ua.pool.ntp.org/us.pool.ntp.org/' /etc/ntp.conf
bash ntp_verify.sh
# Expected: prints NOTICE header + unified diff, then restores the file
# 8. Simulate a stopped daemon, then verify
service ntp stop
bash ntp_verify.sh
# Expected: prints "NOTICE: ntp is not running" and starts the service
# 9. Confirm cron mail delivery (wait ~1 min after a config change)
cat /var/mail/rootTo re-use the container later:
docker start -ai ntp-testTo start fresh:
docker rm ntp-testPrerequisites: VirtualBox and Vagrant installed.
Create a Vagrantfile in any working directory:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y git
SHELL
end# Start and SSH into the VM
vagrant up
vagrant ssh
# Then follow steps 4–9 from Option A above (inside the VM)
sudo -i
git clone https://github.com/<your-username>/task4_2 /root/task4_2
cd /root/task4_2
bash ntp_deploy.sh| Check | Command | Expected result |
|---|---|---|
| NTP installed | dpkg -l ntp |
Package listed |
Only ua.pool.ntp.org in conf |
grep '^pool' /etc/ntp.conf |
Single line: pool ua.pool.ntp.org iburst |
| NTP running | service ntp status |
active (running) |
| Backup exists | ls /etc/ntp.conf.bak |
File present |
| Cron entry registered | grep ntp_verify /etc/crontab |
Entry with * * * * * |
| Verify script — no diff | bash ntp_verify.sh |
No output |
| Verify script — diff | Corrupt conf, then run script | NOTICE header + diff printed, conf restored |
| Verify script — daemon down | service ntp stop && bash ntp_verify.sh |
NOTICE printed, daemon restarted |
- OS: Ubuntu Xenial 16.04 Server
- User:
root - Pre-installed packages:
sendmail - Network: internet access available
- The repository is cloned by URL (e.g.
https://github.com/user/task4_2); a different repository name results in automatic failure. ntp_deploy.shis launched automatically from the repository root; a different script name or subdirectory location results in automatic failure.ntp_verify.shmay also be run manually from the console without waiting for cron.
ntp.confmust differ from the default only in the NTP server section, withua.pool.ntp.orgas the sole configured server.
- Produces no output and does not restart the NTP service.
- Prints the following header line to stdout:
NOTICE: /etc/ntp.conf was changed. Calculated diff: - Outputs the diff in unified format immediately after the header.
- Restores
ntp.confto the correct state (default settings +ua.pool.ntp.orgonly). - Restarts the NTP daemon.
Sample output:
NOTICE: /etc/ntp.conf was changed. Calculated diff:
--- /etc/ntp.conf.bak 2018-03-27 16:45:40.693954805 +0000
+++ /etc/ntp.conf 2018-03-27 16:56:55.723992297 +0000
@@ -20 +20 @@
-pool ua.pool.ntp.org
+pool us.pool.ntp.org- Outputs
NOTICE: ntp is not runningto stdout. - Starts the NTP service.
Note: When triggered via cron, stdout output is delivered to
/var/mail/rootand will be verified there.