You are not logged in.
Pages: 1
Topic closed
Hello All,
Summary:
I have written a shell script to synchronize time from Internet during startup. The command to synchronize time " ntpd -qg " needs sudo. But it is not executing during startup. I think it is a file permission issue. Could anyone of you help me ?
Detailed Description:
Each time when my computer boots up, I want to synchronize my time from Internet. For that I have written a shell script and in order to execute in startup, I have made the changes according to https://wiki.archlinux.org/index.php/Sy … process.3F
The script is simple. Below is the script which I have written
#!/bin/sh
cd /home/user/ #inorder to store the files old_time and updated_time in home folder
date > old_time #store the current time into file old_time
sudo ntpd -qg #command for synchronising the time
date > updated_time #store the updated time into file updated_time
When I reboot my computer, I can see the files old_time and updated_time. So the startup script is running. But the command "sudo ntpd -qg" is not getting executed. Actually my computer doesn't have hardware clock(It is an Raspberry Pi). So each time when it boots, the year is 1970 but after update it gets corrected to 2012. I can see that the year in both the files are same (so "sudo ntpd -qg" is not getting executed ).
If I run the script using " ./script.sh " , it is executing and the time gets updated. For file permission I had executed "chmod +x script.sh". Also I have configured my system in such a manner that sudo never asks for a password.
I think this is a file permission issue. Is there any ways to fix this ? How can I get the sudo command executed ?
It is not an issue with typing passwords since sudo command in my machine doesnot need a password.
Thanks and Best Regards,
Jeffrey Antony
Last edited by Jayfree (2012-10-01 16:42:10)
Offline
Some thoughts:
If systemd is running the script during boot there should be no need to use sudo.
Is your /home mounted before the script runs?
The wiki suggests moving a script to /usr/bin, why run it from /home/you?
You're just jealous because the voices only talk to me.
Offline
Yeah, how exactly are you running it? Are you using SysV or systemd? In either case, during the boot process, things are run as root in general. So if you put it in your rc.conf for example, it would not need sudo, and if you made a service in systemd, it would also not need sudo. You could even make a rc.d file for it, and that too would not need sudo.
Offline
@moetunes: I tried placing the script in /usr/bin folder. But no use. The time is not updated.
@WonderWoofy: I am running my script using systemd. Below is my script
[Unit]
Description=rpi_user
[Service]
ExecStart=/usr/bin/rpi_startup.sh
[Install]
WantedBy=multi-user.target
Any other suggestion ?
I cannot understand why the time is not updating. The internet is connected because above the time update command "ntpd -qg" , if I put an wget for a file, that file gets downloaded.
Regards,
Jeffrey
Offline
Why are you using a script to issue three commands? Why not just write those into the service file? Also, why not just use the ntpd.service, doesn't it already update pretty early?
If you are set on sticking with this plan though, I think you at least need to have the "After=network.target" in the [Unit] section.
Offline
Doesn't the raspberry pi run Arch Arm? I think you should really be asking about this on their forum.
Offline
Doesn't the raspberry pi run Arch Arm? I think you should really be asking about this on their forum.
Indeed. Please see the ARM boards for support for the Pi.
Closing
Offline
Pages: 1
Topic closed