Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 934  / 2 Years ago, sun, july 17, 2022, 6:47:43

On my Ubuntu 10.04 box I (a user, not root) can issue



sudo net time set


and it works great.



I'd prefer that the box get the net time on a more regular basis, or at least each time it gets logged in. So, I tried adding net time set to /etc/profile. That fails. I added stanzas that look like



user ALL=(ALL) NOPASSWD: /usr/bin/net


to /etc/sudoers (using visudo). Didn't help.



I have never touched cron so I have no idea how to add a chron tab. (does seem oxymoronic to depend on the system time to reset the system time.)




  1. What is the best way to do this?

  2. If it's a cron job, I'd appreciate a quick example.

  3. Same questions but for the command service dhcp3-server restart?



(yes, my box gets its address by dhcp, but its dhcp server controls 4 gigabit enet cards attached to high speed cameras. Sometimes, at login? bootup? the dhcp server leaves me seeing only 1 camera.)



Thanks in advance.


More From » cron

 Answers
1

(Yes, I'm adding a second answer.)



From your description, you've added the appropriate line to /etc/sudoers, but you're not invoking sudo in /etc/profile.



The command in /etc/profile needs to be:



sudo net time set


Note that this will run every time any account logs in. Is that what you want, or would it make more sense to put the command in $HOME/.profile?



To make it a cron job, you can add something like this:



0 * * * * *      sudo net time set


to, say, foo.txt, then crontab foo.txt. After that, crontab -l will show you your current cron job(s). With the given parameters, the job will run once an hour; man 5 crontab and adjust as needed. There might be some issues because cron jobs run with a minimal environment, but I don't think /usr/bin/net depends on any environment variables.



Note that, unlike ntpd, this can cause your system's clock to jump backwards, which can cause problems.


[#41026] Tuesday, July 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
splenueak

Total Points: 448
Total Questions: 118
Total Answers: 110

Location: Vanuatu
Member since Mon, Oct 3, 2022
2 Years ago
;