prowl.pl fails when run from crontab

An iPhone client for Growl available on the App Store.
morgman
Harmless
Posts: 2
Joined: Mon Feb 09, 2015 2:10 am

prowl.pl fails when run from crontab

Postby morgman » Mon Feb 09, 2015 2:16 am

I've been successfully running a monitoring script on a raspberry pi that notifies me via prowl.pl
For the longest time I was running the script by hand and then backgrounding it.
Recently I rewrote the script so it could be run from cron.

Once I started running the script from cron I stopped getting notifications.

I was debugging today and discovered that if I run the script by hand in a terminal it works fine.
When the script is run via cron I get the following error:

Notification not posted: Server closed connection without sending any data back at /usr/share/perl5/Net/HTTP/Methods.pm line 345.

I know you have to make special allowances when running from cron.
I added it to my personal crontab not the system one, so it's running as me not root.

But no joy yet... I'm trying to figure out what else I need to get this to work in cron!?

Any suggestions from the experts out there??

Thanks,

MDJ

morgman
Harmless
Posts: 2
Joined: Mon Feb 09, 2015 2:10 am

Re: prowl.pl fails when run from crontab

Postby morgman » Thu Mar 05, 2015 9:19 pm

I will post what ultimately worked for me...
Let me caveat this by saying perl is not my first language... for that matter I wouldn't even say I know enough to be dangerous...
Anyway.

I was trying to figure out why this script, which worked perfectly from the command line, always failed when running from cron.
I verified all the standard issues when running a script for cron (at least all that I'm aware of)
I also discovered that maybe every 30 or 40th run the script WOULD work?!?!!?

I ran strace and compare output from a successful run and a non functioning cron run...
nothing stood out.

When I added extensive logging to the script I noticed one difference between the command line output and the cron output.
I was dumping the UserAgent object that was allocated at the beginning of the script...
In the command line log, the User Agent entry appear in the proper order.
In the cron log, the User Agent entry consistently showed up AFTER the error was returned from the request!?!

Reading in perl suggested to me that LWP::UserAgent->new; was synchronous...

Nonetheless I added the brain dead line: sleep(5); after the User->Agent allocation...

Shockingly the script started working from cron just like it worked when ran from the command line.

I have no idea really what the problem is or if my solution is valid, but I do know that my raspberry pi is back to merrily annoying me with APN's on a regular basis! yay!

If anyone would care to enlighten me as to what in the world is going on, I would much appreciate it!

thank all,

MDJ


Return to “Prowl”

Who is online

Users browsing this forum: No registered users