[ale] help please getting script file to work

Jim Kinney jim.kinney at gmail.com
Wed Feb 15 22:49:23 EST 2012


The first line of a file, script, image or other is typically used to
indixate what the rest of the file is about or how to use it.
I don't know the history behind the syntax of #!/bin/sh but it won't work
without it!
Mike is correct that #!/bin/sh is more generally portable than #!/bin/bash
but I often use many bashisms that wont work in csh, ksh, busybox, nash or
dash so I got in the habit of being clear on the intended shell to run the
script. csh really doesn't play nicely with bash arrays :-)
On Feb 15, 2012 9:28 PM, "Ron Frazier (ALE)" <atllinuxenthinfo at c3energy.com>
wrote:

> **
> Hi Andrew and others,
>
> Thanks for the replies on this thread.  I actually have my script mostly
> working now in the incarnation directly below when I double click it from
> the desktop.  I haven't gotten around to trying to auto boot it yet.  I
> could have posted this question on the NTP questions list at ntp.org,
> however it was more of a Linux specific thing so I posted it here.  I've
> been throwing a bunch of other questions at them anyway.
>
> Two things were keeping my script from not working at all, which are now
> fixed:
>
> The absence of this line: #!/bin/bash, which I'll probably change to
> #!/bin/sh - as Mike W. suggested.  I have no idea what this does!  Looks
> like a comment to me.
>
> Also, I had quotes around all the commands, which the system didn't like.
>
> I posted a thread with this subject yesterday: "how I did Ubuntu + NTPD +
> GPS, but how do I keep it?"  All of my saga is described there.  In answer
> to your question, my GPS is a GlobalSat BU-353 and I'm running Ubuntu 11.04.
>
> Like I said, the script is essentially working.  It's whole purpose is to
> stop NTPD, initialize the USB com port for the GPS, then restart NTPD.  I
> know that the GPS works once that's done.
>
> Right now, I'm having a problem that's driving me insane.  Here's an NTPQ
> printout before running my script.  Notice that the computer is
> synchronized closely to the time servers and there is no GPS.  The top
> server is the current clock.
>
> ron at asus-k52f-1:/etc$ ntpq -p
>      remote           refid      st t when poll reach   delay   offset
> jitter
>
> ==============================================================================
> *nist1-ny.ustimi .ACTS.           1 u  118  128  377   54.015   -3.923
> 10.731
> -216.119.63.113  .ACTS.           1 u   63  128  377   55.535   12.876
> 3.762
> +india.colorado. .ACTS.           1 u   61  128  377   60.914   -7.932
> 2.995
> +ping-audit-207- .ACTS.           1 u  126  128  277   84.008   -6.617
> 5.344
>
> Then, I run the script.  Here is the NTPQ printout shortly after running
> the script:
>
> ron at asus-k52f-1:/etc$ ntpq -p
>      remote           refid      st t when poll reach   delay   offset
> jitter
>
> ==============================================================================
> *GPS_NMEA(5)     .GPS1.           0 l    3    8  377    0.000  595.804
> 88.950
>  nist1-ny.ustimi .ACTS.           1 u    8   64    7   55.065  570.579
> 52.070
>  216.119.63.113  .ACTS.           1 u    6   64    7   55.089  594.824
> 44.885
>  india.colorado. .ACTS.           1 u    7   64    7   60.848  633.795
> 63.543
>  ping-audit-207- .ACTS.           1 u   10   64    7   85.777  576.470
> 45.730
>
> Now, the GPS has appeared, so I know the USB com port is working.
> However, now my clock is ~ 500 ms off from ALL the servers including the
> GPS.  I have the time coming from the GPS fudged so it closely matches the
> NIST servers.  So, I don't really think this is related to the GPS, per se,
> but NTPD is going bonkers or NTPQ is going bonkers.  All I know is I'm
> going bonkers and I cannot figure out where this instant offset is coming
> from.
>
> On Windows, using a recent version of the Windows port of NTPD from Dave
> Hart's website, I can stop the service with it closely synchronized with
> either the GPS or the internet servers, tinker with the configuration, and
> restart NTPD and it picks up right where it left off, with almost no
> additional offset at all.  I MAY have seen it do this once or twice in
> Windows, but I can't remember for sure.  The restart sequence at the bottom
> of my script is supposed to clear up the problem, and that seems to work
> sometimes when I do it manually.
>
> I don't know what's going on here.  Anybody have any clues?  Thanks for
> all the help.
>
> By the way, I'd also like to know how to make my script print things on
> the screen as it progresses through.  In DOS, I'd use ECHO, but I don't
> know the command here.
>
> Sincerely,
>
> Ron
>
>
> ---------------------------
>
> Current version of my script file.
>
> #!/bin/bash
>
> # script file to stop ntpd, initialize the usb gps, then restart ntpd
> # Ron Frazier - 2012-02-15
>
> # stop ntpd
> sudo /etc/init.d/ntp stop
>
> # set up the com port
> log_daemon_msg "Setting /dev/ttyUSB0 comm parameters."
> sudo stty -F /dev/ttyUSB0 57600 igncr clocal -echo -ixon
>
> # set up link to /dev/gps5
> log_daemon_msg "Creating link to /dev/gps5."
> sudo ln -T /dev/ttyUSB0 /dev/gps5
>
> # set the clock
> sudo ntpdate -b nist1-ny.ustiming.org
>
> # start ntpd
> sudo /etc/init.d/ntp start
>
> # wait 5 seconds
> sleep 5
>
> # ---- cycle ntpd again
>
> # stop and restart ntpd
> sudo /etc/init.d/ntp restart
>
> # wait 5 seconds
> sleep 5
>
>
>
> On 02/15/2012 07:43 PM, Andrew Wade wrote:
>
> Can you tell us the model of the USB GPS device?  I see some other posts
> about that same command:  stty -F /dev/ttyUSB0 57600 igncr clocal -echo
> -ixon
>
>  I want to understand which commands you are using are working or not (or
> if you just grabbed them from another source and tried to do the same thing
> in a different Linux OS with no luck)
>
>  Also, what Linux are you using?
>
> On Wed, Feb 15, 2012 at 5:08 PM, Michael H. Warfield <mhw at wittsend.com>wrote:
>
>> On Wed, 2012-02-15 at 14:24 -0500, Jim Kinney wrote:
>> > add a line at the very beginning of the file as below:
>>
>> > #!/bin/bash
>>
>>  #!/bin/sh -
>>
>> If you're not specifically using incompatible bashisms, go with /bin/sh
>> (which is bash anyways) just as a matter of good practice.  Ends up
>> doing the same thing, just better practice.
>>
>> The following dash ('-') is not NEARLY as important on Linux systems as
>> it is on other flavors of *NIX because SUID scripts are not allowed, but
>> it's generally a good idea (BCP) to include that '-' and is generally a
>> standard practice in most "sh/bash/as/ksh" scripts.  There use to be
>> some old security vulnerabilities on SunOS with SUID scripts where the
>> '-' was not included, which is where that practice originated.
>>
>> > better choice to have it start automagically is to write a script
>> modeled
>> > after the ones in /etc/init.d to set up the gps modem and have that
>> process
>> > run before the ntpd is started.
>>
>>  Concur.  Create yourself a nice gps-setup script and link it to
>> 99-gps-setup to take care of those things.  Pouring it into rc.local is
>> an option but not nearly as elegant.
>>
>> Mike
>>
>
>
> --
>
> (PS - If you email me and don't get a quick response, you might want to
> call on the phone.  I get about 300 emails per day from alternate energy
> mailing lists and such.  I don't always see new messages very quickly.)
>
> Ron Frazier
> 770-205-9422 (O)   Leave a message.
> linuxdude AT c3energy.com
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20120215/b96dceee/attachment.html 


More information about the Ale mailing list