Re: [PLUG] Dumb script question
On 4/19/10, Bill Thoen wrote: > Marvin Kosmal wrote: >> All >> >> I was assuming the OP was not running NTPD and was using ntpdate to >> set system time >> >> >> ntpdate can be run manually as necessary to set the host clock, or it >>can be run from the host startup script to set the clock at boot >> time. >>This is useful in some cases to set the clock initially before >> starting >>the NTP daemon ntpd. It is also possible to run ntpdate from a >> cron >>script. However, it is important to note that ntpdate with >> contrived >>cron scripts is no substitute for the NTP daemon, which uses >> sophisti- >>cated algorithms to maximize accuracy and reliability while >> minimizing >>resource use. Finally, since ntpdate does not discipline the host >> clock >>frequency as does ntpd, the accuracy using ntpdate is limited. >> >> >> So I don't see anything wrong with running ntpdate or rdate once a day >> if you want.. Given NTPD would be better... Probably not a critical >> issue?? >> > It all depends on how much your time gets shifted suddenly when you use > ntpdate. I learned the hard way when that happens all Hell breaks loose > on a server. If your time kicks backwards by as little as 110 seconds > all of a sudden, Dovecot will panic and kill itself-- it even announced > in the log that it was "going to kill myself"), so you lose your IMAP > connections right away. Other software starts whinging too. The RBL spam > blocker I had running suddenly started "synchronizing" with its friends > in Berkeley and elsewhere every few minutes (and since I didn't know at > the time what this "synchronizing" was all about and coincidentally I > was just then getting hit with a super large volume of spam (53Mb as it > turned out, over a couple of hours ). Every daemon starting writing log > entries at once. Then the Amavis daemon (virus checker) gave up its > ghost and keeled over dead. I was also getting hundreds of error > messages from Named like: "validating @0x7f82840008c0: 115.in-addr.arpa > DNSKEY: bad cache hit (115.in-addr.arpa/DS): 1 Time(s)". XNTPD got > killed too after complaining about "no servers reachable", and > "...cannot be used reason: temporary failure in name resolution." (the > DNS stopped working too.) > > I'm not a wizard at the sysadmin stuff so I 'm not sure if it was the > boatload of spam that washed in over the transom just as the time > change incident occurred, or if it was just the sudden time shift alone, > or both, but it really rocked /my/ boat. But as I RTFM'ed the Dovecot > docs later ttrying to figure out WTF happened the section in > TimeMovedBackwards on Dvoecot's wiki > (http://wiki.dovecot.org/TimeMovedBackwards) explains all the horrible > things that could happen and make Dovecot's best option being just to > fall upon its sword. > > But I did learn one lesson clearly. Don't fool around with 'date' > --especially the -s option-- when you're logged in as root so you can > tinker with a script that has to run as root! > > Bill Thoen > GISnet - www.gisnet.com > 1401 Walnut St., Suite C > Boulder, CO 80302 > 303-786-9961 tel > 303-443-4856 fax > OK I can see that running NTPD is the only thing to do Thanks for the examples Marvin ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
Marvin Kosmal wrote: > All > > I was assuming the OP was not running NTPD and was using ntpdate to > set system time > > > ntpdate can be run manually as necessary to set the host clock, or it >can be run from the host startup script to set the clock at boot time. >This is useful in some cases to set the clock initially before starting >the NTP daemon ntpd. It is also possible to run ntpdate from a cron >script. However, it is important to note that ntpdate with contrived >cron scripts is no substitute for the NTP daemon, which uses sophisti- >cated algorithms to maximize accuracy and reliability while minimizing >resource use. Finally, since ntpdate does not discipline the host clock >frequency as does ntpd, the accuracy using ntpdate is limited. > > > So I don't see anything wrong with running ntpdate or rdate once a day > if you want.. Given NTPD would be better... Probably not a critical > issue?? > It all depends on how much your time gets shifted suddenly when you use ntpdate. I learned the hard way when that happens all Hell breaks loose on a server. If your time kicks backwards by as little as 110 seconds all of a sudden, Dovecot will panic and kill itself-- it even announced in the log that it was "going to kill myself"), so you lose your IMAP connections right away. Other software starts whinging too. The RBL spam blocker I had running suddenly started "synchronizing" with its friends in Berkeley and elsewhere every few minutes (and since I didn't know at the time what this "synchronizing" was all about and coincidentally I was just then getting hit with a super large volume of spam (53Mb as it turned out, over a couple of hours ). Every daemon starting writing log entries at once. Then the Amavis daemon (virus checker) gave up its ghost and keeled over dead. I was also getting hundreds of error messages from Named like: "validating @0x7f82840008c0: 115.in-addr.arpa DNSKEY: bad cache hit (115.in-addr.arpa/DS): 1 Time(s)". XNTPD got killed too after complaining about "no servers reachable", and "...cannot be used reason: temporary failure in name resolution." (the DNS stopped working too.) I'm not a wizard at the sysadmin stuff so I 'm not sure if it was the boatload of spam that washed in over the transom just as the time change incident occurred, or if it was just the sudden time shift alone, or both, but it really rocked /my/ boat. But as I RTFM'ed the Dovecot docs later ttrying to figure out WTF happened the section in TimeMovedBackwards on Dvoecot's wiki (http://wiki.dovecot.org/TimeMovedBackwards) explains all the horrible things that could happen and make Dovecot's best option being just to fall upon its sword. But I did learn one lesson clearly. Don't fool around with 'date' --especially the -s option-- when you're logged in as root so you can tinker with a script that has to run as root! Bill Thoen GISnet - www.gisnet.com 1401 Walnut St., Suite C Boulder, CO 80302 303-786-9961 tel 303-443-4856 fax ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
On Sun, 2010-04-18 at 21:44 -0700, John Jason Jordan wrote: > On Sun, 18 Apr 2010 20:24:15 -0700 > John Jason Jordan dijo: > > >On Sun, 18 Apr 2010 20:16:46 -0700 > >wes dijo: > > > >>how do you "change to root" ? I'm betting it's with sudo su rather > >>than just su. When you use sudo, it asks for jjj's password instead of > >>root's. > > > > So I edited my script and put sudo in front of both commands, made a > gnome-panel icon to launch it in a terminal, and it is working fine. > I'll run it whenever I notice the clock doesn't match my watch by > enough to care about. There is a handy little utility called gksudo thats acts as a graphic wrapper to sudo. You can do something like: gksudo --message "fix the time" your-script.sh and it will pop up a window prompting you for your password so you don't need to launch a terminal. Though as has been pointed out elsewhere NTPD is the tool to use if you have a permanent Internet connection. While I'm on the subject it is recommended you use the local pool.ntp.org server i.e. us.ntp.pool.org as you will get a better result and it avoids overloading the main servers. Paul M > ___ > PLUG mailing list > PLUG@lists.pdxlinux.org > http://lists.pdxlinux.org/mailman/listinfo/plug ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
All I was assuming the OP was not running NTPD and was using ntpdate to set system time ntpdate can be run manually as necessary to set the host clock, or it can be run from the host startup script to set the clock at boot time. This is useful in some cases to set the clock initially before starting the NTP daemon ntpd. It is also possible to run ntpdate from a cron script. However, it is important to note that ntpdate with contrived cron scripts is no substitute for the NTP daemon, which uses sophisti- cated algorithms to maximize accuracy and reliability while minimizing resource use. Finally, since ntpdate does not discipline the host clock frequency as does ntpd, the accuracy using ntpdate is limited. So I don't see anything wrong with running ntpdate or rdate once a day if you want.. Given NTPD would be better... Probably not a critical issue?? Back in the old days I would wait for the noon train to go by and then set the clocks in the house and the computer at the same.. That was an example of a PERFECT system. YMMV Marvin On 4/19/10, Randal L. Schwartz wrote: >> "Marvin" == Marvin Kosmal writes: > > Marvin> Good One > > Where "Good" here is "bad". See my other post. > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > http://www.stonehenge.com/merlyn/> > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion > > ___ > PLUG mailing list > PLUG@lists.pdxlinux.org > http://lists.pdxlinux.org/mailman/listinfo/plug > ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
> "Marvin" == Marvin Kosmal writes: Marvin> Good One Where "Good" here is "bad". See my other post. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
> "John" == John Jason Jordan writes: John> ntpdate 0.pool.ntp.org John> hwclock --systohc You should be running ntpd, not using ntpdate. ntpdate is just for gross corrections at bootup. Using it *after* booting will likely break things at mysterious times, like make builds. ntpd knows how to "drift" the time clock slightly faster or slower so that time never goes backwards or skips grossly forwards. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
Good One Marvin On 4/18/10, Hal Pomeranz wrote: > Actually, rather than using your script, you should just be able to go > to System -> Administration -> Time&Date and configure your system to > automatically synchronize to Internet time servers. > > Alternatively, the cron entry you're looking for is: > > 0 * * * * /usr/sbin/ntpdate pool.ntp.org > > Use "sudo crontab -e" to add this line to root's crontab using your > favorite text editor. It will sync your clock at the top of every > hour against a random selection of time servers from pool.ntp.org. > > -- > Hal Pomeranz, Founder/CEO Deer Run Associates h...@deer-run.com > Network Connectivity and Security, Systems Management, Training > ___ > PLUG mailing list > PLUG@lists.pdxlinux.org > http://lists.pdxlinux.org/mailman/listinfo/plug > ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
Actually, rather than using your script, you should just be able to go to System -> Administration -> Time&Date and configure your system to automatically synchronize to Internet time servers. Alternatively, the cron entry you're looking for is: 0 * * * * /usr/sbin/ntpdate pool.ntp.org Use "sudo crontab -e" to add this line to root's crontab using your favorite text editor. It will sync your clock at the top of every hour against a random selection of time servers from pool.ntp.org. -- Hal Pomeranz, Founder/CEO Deer Run Associates h...@deer-run.com Network Connectivity and Security, Systems Management, Training ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
> The big trick with cron is that it doesn't have a normal env so you > tend to have to use full paths to everything, or manually set the > environment prior to running the command. It's also tricky debugging > because you don't get to tell it to run now. You usually have to set > the frequency of how often it runs really low until you figure it out. A useful trick whenever you're invoking executables in an unknown environment is to simply run env and redirect it to a file. When I run the cron command setup as * * * * * env > mycrontab.env using crontab I get the following in a file named mycrontab.env in my home directory on a Ubuntu 8.04LTS box: HOME=/home/neals LOGNAME=neals PATH=/usr/bin:/bin SHELL=/bin/sh PWD=/home/neals Not a lot there, eh? How you hook sudo into all of this is an exercise left to interested parties. ;) FYI, NealS ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
On Sun, Apr 18, 2010 at 9:44 PM, John Jason Jordan wrote: > On Sun, 18 Apr 2010 20:24:15 -0700 > John Jason Jordan dijo: > >>On Sun, 18 Apr 2010 20:16:46 -0700 >>wes dijo: >> >>>how do you "change to root" ? I'm betting it's with sudo su rather >>>than just su. When you use sudo, it asks for jjj's password instead of >>>root's. >>> >>>There are 2 solutions available: change your script to use sudo in >>>front, or just have the commands run as root automatically on a >>>schedule via cron. >> >>Thanks for the heads up. Of course sudo su uses jjj's password, and I >>must have done that, although I could swear I used just su. I say that >>I must have done that because just now I tried su and got an >>authentication error. I suspect there is no root password set on the >>computer. I think Ubuntu does not set a root password by default. >> >>And, after thinking about it, the cron approach sounds simpler. I could >>set it to run just once a month, which would be sufficient to keep the >>clock reasonably current. >> >>Off to figure out cron. > > After an hour of trying to make sense of cron I gave up. I'm sure it's > an amazing tool that will do wonderful things, but I don't need to do > wonderful things. > > I installed gnome-schedule, which appears to be a GUI front end for > cron. Unfortunately, the documentation does not match the application > and there appears to be no way to run a command with it as root or as > superuser. > > So I edited my script and put sudo in front of both commands, made a > gnome-panel icon to launch it in a terminal, and it is working fine. > I'll run it whenever I notice the clock doesn't match my watch by > enough to care about. > ___ > PLUG mailing list > PLUG@lists.pdxlinux.org > http://lists.pdxlinux.org/mailman/listinfo/plug > When you find the time to explore cron Jason it's well worth the time spent. Maybe we could do a quick hits basics during one of the monthly meetings if we don't have speakers lined up to go over things like cron etc. Drew- ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
On Sun, 18 Apr 2010 20:24:15 -0700 John Jason Jordan dijo: >On Sun, 18 Apr 2010 20:16:46 -0700 >wes dijo: > >>how do you "change to root" ? I'm betting it's with sudo su rather >>than just su. When you use sudo, it asks for jjj's password instead of >>root's. >> >>There are 2 solutions available: change your script to use sudo in >>front, or just have the commands run as root automatically on a >>schedule via cron. > >Thanks for the heads up. Of course sudo su uses jjj's password, and I >must have done that, although I could swear I used just su. I say that >I must have done that because just now I tried su and got an >authentication error. I suspect there is no root password set on the >computer. I think Ubuntu does not set a root password by default. > >And, after thinking about it, the cron approach sounds simpler. I could >set it to run just once a month, which would be sufficient to keep the >clock reasonably current. > >Off to figure out cron. After an hour of trying to make sense of cron I gave up. I'm sure it's an amazing tool that will do wonderful things, but I don't need to do wonderful things. I installed gnome-schedule, which appears to be a GUI front end for cron. Unfortunately, the documentation does not match the application and there appears to be no way to run a command with it as root or as superuser. So I edited my script and put sudo in front of both commands, made a gnome-panel icon to launch it in a terminal, and it is working fine. I'll run it whenever I notice the clock doesn't match my watch by enough to care about. ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
> And, after thinking about it, the cron approach sounds simpler. I could > set it to run just once a month, which would be sufficient to keep the > clock reasonably current. > > Off to figure out cron. The big trick with cron is that it doesn't have a normal env so you tend to have to use full paths to everything, or manually set the environment prior to running the command. It's also tricky debugging because you don't get to tell it to run now. You usually have to set the frequency of how often it runs really low until you figure it out. -- teknotus Take Notice (503) 409-1735 ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
On Sun, Apr 18, 2010 at 08:24:15PM -0700, John Jason Jordan wrote: > I must have done that because just now I tried su and got an > authentication error. I suspect there is no root password set on the > computer. I think Ubuntu does not set a root password by default. That is correct. It expects everything to be done via sudo. -- Michael Rasmussen, Portland Oregon Trading kilograms for kilometers since 2003 Be appropriate && Follow your curiosity http://www.jamhome.us/ The Fortune Cookie Fortune today is: Q: What looks like a cat, flies like a bat, brays like a donkey, and plays like a monkey? A: Nothing. ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
On Sun, 18 Apr 2010 20:16:46 -0700 wes dijo: >how do you "change to root" ? I'm betting it's with sudo su rather >than just su. When you use sudo, it asks for jjj's password instead of >root's. > >There are 2 solutions available: change your script to use sudo in >front, or just have the commands run as root automatically on a >schedule via cron. Thanks for the heads up. Of course sudo su uses jjj's password, and I must have done that, although I could swear I used just su. I say that I must have done that because just now I tried su and got an authentication error. I suspect there is no root password set on the computer. I think Ubuntu does not set a root password by default. And, after thinking about it, the cron approach sounds simpler. I could set it to run just once a month, which would be sufficient to keep the clock reasonably current. Off to figure out cron. ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
On Sun, Apr 18, 2010 at 07:55:31PM -0700, John Jason Jordan wrote: > #! /bin/bash > su #'cause only root can set the time > ntpdate 0.pool.ntp.org > hwclock --systohc > > When I try to run it as jjj it asks for root password, I enter it, > and then I get an authentication error. If I change to root first and > then run it, it runs fine, and without prompting for root password. > > It must be the su line. How do I make a script run as root? Or can I > fiddle with the permissions so jjj has permission to set the time, then > just remove the su line from the script and forget about running it as > root? Choices, choices, choices Change the script to: #!/bin/bash sudo ntpdate 0.pool.ntp.org sudo hwclock --systohc or Change the script to: #!/bin/bash ntpdate 0.pool.ntp.org hwclock --systohc and invoke it by `sudo ` or su crontab -e exit or sudo chown root sudo chmod +x sudo chmod u+s The last one is what you asked for. -- Michael Rasmussen, Portland Oregon Trading kilograms for kilometers since 2003 Be appropriate && Follow your curiosity http://www.jamhome.us/ The Fortune Cookie Fortune today is: You recoil from the crude; you tend naturally toward the exquisite. ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
how do you "change to root" ? I'm betting it's with sudo su rather than just su. When you use sudo, it asks for jjj's password instead of root's. There are 2 solutions available: change your script to use sudo in front, or just have the commands run as root automatically on a schedule via cron. -wes On Sun, Apr 18, 2010 at 7:55 PM, John Jason Jordan wrote: > I have a desktop computer (Intrepid x86_64) that runs for months and > months and is never rebooted. (All it does is play the radio and and the > occasional movie, and act as a backup in case I seriously goober up my > laptop.) I noticed this afternoon that its time was off by five > minutes. I know that I can reset the time from an NTP server by > rebooting, but that is a pain. Google told me that I can reset the time > with: > > ntpdate 0.pool.ntp.org > hwclock --systohc > > So I decided to use my amazing knowledge of bash scripting learned at > the recent class to create a little script with an icon next to the > clock display in the Gnome panel. My script is: > > #! /bin/bash > su #'cause only root can set the time > ntpdate 0.pool.ntp.org > hwclock --systohc > > When I try to run it as jjj it asks for root password, I enter it, > and then I get an authentication error. If I change to root first and > then run it, it runs fine, and without prompting for root password. > > It must be the su line. How do I make a script run as root? Or can I > fiddle with the permissions so jjj has permission to set the time, then > just remove the su line from the script and forget about running it as > root? > ___ > PLUG mailing list > PLUG@lists.pdxlinux.org > http://lists.pdxlinux.org/mailman/listinfo/plug > ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug
Re: [PLUG] Dumb script question
John Jason Jordan wrote: > I have a desktop computer (Intrepid x86_64) that runs for months and > months and is never rebooted. (All it does is play the radio and and the > occasional movie, and act as a backup in case I seriously goober up my > laptop.) I noticed this afternoon that its time was off by five > minutes. I know that I can reset the time from an NTP server by > rebooting, but that is a pain. Google told me that I can reset the time > with: > > ntpdate 0.pool.ntp.org > hwclock --systohc > > So I decided to use my amazing knowledge of bash scripting learned at > the recent class to create a little script with an icon next to the > clock display in the Gnome panel. My script is: > > #! /bin/bash > su #'cause only root can set the time > ntpdate 0.pool.ntp.org > hwclock --systohc > > When I try to run it as jjj it asks for root password, I enter it, > and then I get an authentication error. If I change to root first and > then run it, it runs fine, and without prompting for root password. > > It must be the su line. How do I make a script run as root? Or can I > fiddle with the permissions so jjj has permission to set the time, then > just remove the su line from the script and forget about running it as > root? > Have you tried putting the su in front of ntpdate on the same line? -- Regards, Dick Steffens ___ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug