Time Synchronization (BASH)

hi

I am running opensuse 12.1. i synchronize my time from the command line using the following command:

ntpdate pool.ntp.org

however, to run this command i need to be logged in as superuser.

how can i write a bash script that can login as root and run this command. (i want to set this script to run as a cron task, hence…)

any help would be appreciated!

db

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don’t do anything special with the script, just run it as ‘root’ from
crontab:

In /etc/crontab:

0 * * * * root /path/to/your/script/settime.sh

It should run at the top of every hour with the definition above.

Good luck.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJQMkkjAAoJEF+XTK08PnB5vnAP+wQCr1Tu+rZ8dHDdqJ65Ja5k
D/V4xK0f7+Q1Sbmx/MRWDFAPbCnp2VSNMTOJRDXuv5xYIWgNTOjWhGZaqpqpfOmF
lmGzWe3sqjzKv0bV+9GkDA8u8usSW0WWqNVxdl/Kcu8Pi9vHIZAhHbwlb0SUAGjx
CQfmtFpOIocxQ4iJsEWDKh5RiHz1/29icCTocxUyR5IaII07C8lVEnIkX2F+WSCo
5DyS8e/fUoyjr9hlVY1+EVM+yEfHKwDvN7IpshPZX/lMs7Wk5uN2CuSG7nCpwefV
ZCrfVqkdjEWG27e4QJqvUeaPAUOmkVT039kRRx0uzQ7dKX8+ZL0ROM3NrDDyr3vd
pML6mKab5HOQzoxDVIfdI7PPneOip0FgvpSHsCJCAuTzzFPgth1NAJBRylX2vvWk
6aZGc769P7JHy7TSUgiWvK4F5jODuKAxglShMOln/WgXyLSkuaOWe2CotH0p9Voe
AdXQEZbZ5EK/FKBTrYQlvG9vNGWfpqaYsiUcCY38yoqAedpqvoCvyOf1d6LwPy4z
lyP5aIn3TzenBxxwv0kUaIiz+G3T9DvD1wB59sx2rsZJSzD6DmsJ4tTTG7MLBLG4
hbJ1v+OxwuoFZbD8d1Qze3ci4N68lfPCO9UgwTal2y64jm41JSswI7vLWahl8yjv
o7asDi1H+7kdYBqBVpip
=9PGG
-----END PGP SIGNATURE-----

blackbird sr71 wrote:
> I am running opensuse 12.1. i synchronize my time from the command line
> using the following command:
>
>
> Code:
> --------------------
> ntpdate pool.ntp.org
> --------------------
>
>
> however, to run this command i need to be logged in as superuser.
>
> how can i write a bash script that can login as root and run this
> command. (i want to set this script to run as a cron task, hence…)

You don’t need a bash script to run a command as root. Just put the
command in root’s crontab.

But in this case, why don’t you simply use the ntp daemon? Use YaST to
set it up.

Why not using ntpd rather than ntpdate? Just enable this service, for example using Yast -> System Services -> ntp and “Yes”.
If you want to use ntpdate, you have to put it in a cron job (not in a bash script).

thank you! the ntp daemon does the trick!
appreciate your help,
db