Im writing or trying to write a script that will add some NTP servers to 22.04 server.
Setntpclient()
{
sudo cp /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.conf.bk_`date +%Y%m%d%H%M`
echo
sudo chmod 664 /etc/systemd/timesyncd.conf #setting to rw for user and group
sudo cat > /etc/systemd/timesyncd.conf <<EOF
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the timesyncd.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# See timesyncd.conf(5) for details
[Time]
NTP=ntp0.domain.com ntp1.domain.com
FallbackNTP=IpAdd1 IpAdd2
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
EOF
sudo chmod 644 /etc/systemd/timesyncd.conf
sudo systemctl unmask systemd-timedated.service
sudo systemctl restart systemd-timesyncd.service
sudo timedatctl set-timezone "Europe/London"
echo timedatectl status
}
Setntpclient
Now when I go to restart the systemd-timesyncd.service I get an error.
Permission denied
Failed to restart systemd-timesyncd.service: Unit systemd-timesyncd.service is masked.
So I added the "sudo systemctl unmask systemd-timedated.service" to the script.
Now from reading what I am guessing is when you run a shell script it runs it from /tmp and this maybe causing the issue? If so what is the way around this?
Update to clarify what I'm seeing
ntp.conf is being updated but when it comes time to restart the timesynd service its fails with the error.