Hughesnet Community

Spot the rookie error

cancel
Showing results for 
Search instead for 
Did you mean: 
MarkJFine
Professor

Spot the rookie error

Europe changed time at 2am this weekend (we do the same next weekend). But a PHP script routine that I run on a US server to detect time changes in London was broke. I've already fixed it, but who else can find the problem (sometimes I'm such a dummy)...

 

date_default_timezone_set('UTC');

$time_adj = strtotime("now") - strtotime("Europe/London");
if ($time_adj = 3600) {
    $time_lbl = 'BST';
} else {
    $time_lbl = 'GMT';
}


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.
16 REPLIES 16
donsjgm
Junior

Hi Mark,

 

I don't do PHP so I'm just shooting in the dark but to have some fun with it my guess is it should be 

 

=>

Don  🙂

Close...

 

In the line: if ($time_adj = 3600) {

=     (single '=') just assigns 3600 to $time_adj and the 'if' always evaluates true because 3600 is greater than 0, so it's always BST (D'oh). It should have been:

==   (double '=') which actually tests whether $time_adj is equal to 3600 (3600 sec = 1 hr), meaning the difference between current London time and UTC is 1 hr, or BST. Otherwise the difference would be zero, or UTC/GMT.

 

Stupid thing gets me every time, just like remembering to end a line with a semi-colon.


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

Well I had the right line.

I knew that the single '=' was the problem but wasn't sure how to implement the test.

Like I said, "it was just for fun" and I came close.

I've been fighting with a property list (plist) to make a Mac update during bonus hours.

There's been several ppl who have asked how.

I can't seem to find the 'bug' and it may be OS version specific. So far idk.

 

It's something like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>YourMac.name.here.SftwrUpdt</string>
    <key>ProgramArguments</key>
    <array>
        <string>softwareupdate</string>
<string>--Download</string>
<string>--All</string>        
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>02</integer>
<key>Minute</key>
        <integer>00</integer>

    </dict>
    <key>StandardErrorPath</key>
    <string>/Users/donsjgm/Library/Application\ Support</string>
    <key>ProductPaths</key>
    <string>/Users/donsjgm/Library/Application\ Support</string>
</dict>
</plist>

Interesting. Is it kicking off and giving an error, or just not kicking off?

If it's kicking off, it might need to be sudo'd.

Also, not sure what the '--schedule' switch really does, but it might have something to do with it.

 

Looking at Creating Launch Daemons and Agents:

I'm guessing you've seen the example for StartCalendarInterval. I'm also assuming the file is in the right folder (one of ~/Library/, /Library/, or /System/Library/; in either the LaunchDaemons or LaunchAgents folders) with the right permissions.


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

It's not kicking off, it reports "Invalid property list".

it's in /Library/LaunchDaemons and should start with sudo launchctl load /Library/LaunchDaemons/YourMac.name.here.SftwrUpdt.plist

I finally got tired and set it aside for now.

I've scrutinized it for syntax errors and searched for the reason that it's invalid.

Different versions of OS X use different file locations and the finished (working) plist might be version dependant, idk.

the "softwareupdate" command works from terminal so thus far I just haven't figured it out.

I'll have to go back and study Creating Launch Daemons and Agents to see what I might be missing.

I was going to use cron but since it's depreciated and I wanted to help as many ppl as possible I went with Launchd.

Just a work in progress - I thought I would share with you.

 

Don  🙂

Hmm... I copied/pasted into a text file, then opened it in Xcode and it seemed to read like a proper plist, so the 'invalid' thing is very strange.

Sounds like my kind of challenge. I'll kick it around as well to see what I can get working. Maybe together we can solve this.

 

I agree that this can ultimately be very helpful to other Mac users that want to automate updates in the Bonus period - or for anyone that just wants to do things overnight for that matter.

 

I can even create a frontend in Xcode that creates/positions the file with the desired softwareupdate options once we figure out the what and where.


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

FWIW I just opened a terminal and pounded out the code following sample structures of course.

I've done some more searching (do my best thinking in the middle of the night... uninterrupted LOL) and I don't think it has to have a listener. (but maybe)

It might need a keep alive but that can be added (if necessary) after It will load.

I've played around with the StandardErrorPath and the StandardOutputPath thinking (at first) the problem might be there.

Apparently it's not that easy a task or someone somewhere would have written it.

It's clearly something that satellite users could benefit from.........

Hopefully together we can do this for the community.

I'll keep you posted with any progress here.

 

Good Luck

Don  🙂

Try this, just for grins:

1. Create a UTF-8 text file called com.example.softwareupdate.plist and put this in it:
-----8<----

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.example.softwareupdate</string>
    <key>ProgramArguments</key>
    <array>
        <string>softwareupdate</string>
        <string>--download</string>
        <string>--all</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>2</integer>
        <key>Minute</key>
        <integer>10</integer>
    </dict>
</dict>
</plist>

-----8<----

2. Move the file to ~/Library/LaunchAgents/

3. Change the privileges to owner, rw only:

    chmod 600 com.example.softwareupdate.plist

4. See if that works


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

Mark,

 

It loaded just fine!  🙂

I'm caught for time right now and haven't gotten to check it out completely

Clearly a case of less is more ( might not be the same for older OSs)

It will be interesting to see if /LaunchAgents is the right directory but after proofing it if it performs as expected we need to author the solution and give it to the community.

I'll do some testing with it as soon as possible.

NICE WORK  👍

 

Don  🙂

Apparently LaunchAgents gives you more flexibility for running things like crons that don't need a GUI, whereas LaunchDaemons is a bit more restrictive.

I'm unsure if the filename had anything to do with it. I just made sure it was the same or close to what the Label was.

Also, aparently ownership and persmissions are important depending upon where it goes:
1. If under ~/Library, the permissions have to be set with you as owner and unaccessible by group or world.

2. If under /Library or /System/Library, the permissions have to be set as root, similarly using 600 or 400.

 

Cool, so, on to the next phase!


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

I was also able to load it under LaunchDaemons.

I'm not sure but I'm under the impression that LaunchAgents require user interaction.

In either case it loads and unloads without a problem.

I'm unable to catch a PID using both the activity monitor and the console.

I changed the StartCalenderInterval and watched as it passed the time however currently there are no updates pending.

 

In what little time I had been looking into it, before I saw you revision, I had come across the possibility that it might need some form of the following:

 

<key>com.apple.private.AuthorizationServices</key>

<array>
<string>system.download.apple-software</string>

<string>com.apple.softwareupdate.manage_daemon</string>
</array>

 

Regardless, thus far everything seems great. Might have to add the KeepAlive or wait until there's an update. (experimentation needed)

I can see in the logs where it loads and unloads but the fact that it's not showing a PID makes me think although it's loading, it's not running.

Dunno. May be how it spawns the process. Should be something in the log if there's a spawning error.

Been busy with other things, but will test it more over the weekend.


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

Hey Mark,

I've been waiting for an update to be available to "smoke test" it. For a while it seemed they were coming pretty often.

I just got notice of an available update (this evening) but I won't be able to check it out until the weekend.

I have seen that there are (supposedly) some settings in the GUI that have to be changed from my regular settings. With that, I'm first going to try the version you sent without modifications and we'll see what happens.

I've had a couple in the past few days (Xcode Command Line Tools, OneNote), but forgot to try it. Been so busy it completely slipped my mind.


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.

Hey Mark,

 

I got the plist to run but haven't gotten sucessfull results yet.

 

Changing "download" to "update" did the trick however I thus far am getting the following message in the console:

 

Service exited with abnormal code: 1

 

It's being sort of ornery. Kind of looking for a missing or incorrect symbol in assembly code. Lol

 

I'm not able to give it full time attention so the process is taking longer than I initially thought but my limited sucess has convinced me that it can be done.

tbh, I haven't seen enough actual updates for it to work.


* Disclaimer: I am a HughesNet customer and not a HughesNet employee. All of my comments are my own and do not necessarily represent HughesNet in any way.