Crontab [RESOLVED]

  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

Right, so I made myself a handy little script that pings servers to find out if they're up, and if they're not it sends a twitter update to an account I'm following, I get texted telling me, I fix.

However, the integral part of this is it checking. I would prefer to do this with crontab rather than sleep.

So, I added the cron entry to the perl script, as follows:
Code: [ Select ]
* * * * * perl /etc/twitter/checkupstate.pl


crontab -l verifies the entry is present.
So it is supposed to check every minute. Well, within the script I have a logging function, which when tested (direct start) works, but crontab is not starting the program at all. Any ideas why?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

Did you look in /var/log/cron for any errors?
  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

There is no cron log in that directory.
  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

Try the full path /usr/bin/perl or whatever it is. Is the cronjob running as root?
  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

Updated to full path. No change.

It is not running as root.

I'm running Ubuntu Server 8.10 Intrepid by the way.
  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

I happened to have an Ubuntu 8.10 box, so I connected it, booted it & ran man cron. One thing that I noticed that in some cases,
/bin/sh is needed before the command. Try that.
  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

Code: [ Select ]
* * * * * /bin/sh /usr/bin/perl /etc/twitter/checkupstate.pl

Now, I get mail from the cron with the following message:
Code: [ Select ]
/usr/bin/perl: 1: Syntax error: word unexpected (expecting ")")


Yet when I cd to /etc/twitter or cd to / and run the script (perl checkupstate.pl) it all works fine (Logs output).

Update: Played around with the command, and the /bin/sh is what's causing this error... why?
  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

At least /bin/sh started the cron job which is an improvement. You may not need the /usr/bin in front of the perl command now.

OR

Try /bin/sh -c

Or

Try a different shell /bin/bash

I don't see csh or ksh installed on my box but I'm sure it can be installed.
  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

The /usr/bin is needed, otherwise I get an error saying perl couldn't be found.

Tried with /bin/sh -c and got no result.

Tried with /bin/bash and got a mail message saying "/usr/bin/perl: /usr/bin/perl: cannot execute binary file"

*sigh* Guess I'm going to have to use sleep(60)...
  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

=/ I never said this, but I'm not a Perl programmer. It's a language native to Linux and I have Google, so I got it all working. It's similar to alot of languages anyhow.

Now to start a thread on how to write a Perl Daemon, because I can't get that working...
  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

The perl script is working. It's just getting it to run from the cron job.

http://www.usats.com/learn/crontab.shtml
  • jammer2552
  • Graduate
  • Graduate
  • User avatar
  • Posts: 139

Post 3+ Months Ago

:D

Checked for the existence of cron.allow and cron.deny, neither were present, which means only root was allowed to run cron.

So, one "sudo crontab -e" later, it's running perfectly!

Thanks for that link, help, and patience Don. :)
  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

FANTASTIC! Glad to hear it.

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 38 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.