Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 8 of 8

This is a discussion on Help with cron job needed in the Shared & Semi-Dedicated forum
Hi, Can anybody help me out with a cron job? What I'm trying to do is update a few things automatically on the weekends. The ...

  1. #1
    JPC Senior Member
    Join Date
    Feb 2003
    Posts
    57

    Help with cron job needed

    Hi,

    Can anybody help me out with a cron job? What I'm trying to do is update a few things automatically on the weekends.

    The idea would be to delete a folder and then rename another folder.
    Or, just renaming the folders would work and I could delete the unwanted one later "manually".

    If anybody could help me out I would appreciate it. I don't have the foggiest idea where to start.

    My apologies if this is the wrong place to ask such a question.

    Thank you very much for your time.

    Jeff

  2. #2
    JPC Senior Member
    Join Date
    Feb 2003
    Posts
    57

    Red face Figured it out

    If anybody is interested, I figured out how to do it. The simplest way seems to be using perl to rename the folders (in my case) and use a cron job to run the perl scripts.

    I'm a real bad hack when it comes to perl, but I got this to work:
    Code:
    The syntax for renaming: rename "oldname","newname";
    I used the full server paths and loaded the script in the cgi-bin(755) and set the permissions on the folder to be renamed to 777.
    Copy of the script I made:
    
    #!/usr/bin/perl
    
    rename "server path to folder to rename","server path to renamed folder";
    Like I said, I'm not good with perl, but it works. I also tried it with another line in the code [exit;] but it didn't seem to matter, it worked with and without that. When I ran either one from a browser, I got internal server error but the script still did what it was supposed to. When ran using the cron job, no errors were generated. Maybe somebody more adept at perl can enlighten me as to what that's all about.

    Then it was just a matter of setting up the cron job in the control panel; I found the info needed for setting times, etc. here:
    http://www.adminschoice.com/docs/crontab.htm

    Anyway, I'm getting more automated now, which was my goal.

    Jeff

  3. #3
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Jeff,

    As far as the peral script, that's exactly how CRON is supposed to work. The reason why you're getting script errors in the browser is because you aren't sending the proper headers that Apache expects a script to send. Its not a big deal here because there is no user interface to your script, bu in a typical CGI you'd use

    Code:
    print("Content-type: text/html\n\n");
    before you send any output to the browser. That tells Apache to expect HTML from your script.

    exit, as you discovered, isn't required. It is often used to tell a script to end before it finishes. For example, if an error occurs you might want to print an error message and stop further processing--then you would use exit. Scripts end automatically when there is no more code for them to run (ie when they get to the end of the file), so an explicit "exit" at the very end is not necessary.

    One suggestion I would make is to move your script out of your public_html directory. The way you have it right now, anyone who can figure out that URL could run your script and might mess up what you are collecting (since I don't know what you're deleting, I can't comment on the side effects). Personally, I put these types of scripts in a directory called "bin" in my home directory. Set the script's permission to 700 so that only you can run it (cron jobs run under your user id) and change the command in CPanel to use (assuming you're using "bin" as I would) "/home/YOURUSERNAME/bin/YOURSCRIPTNAME" (if you currently have a GET in the command, remove it). Now only you (or your cron job) will be able to run the script, so it will be more secure.

    Let me know if you have any more questions or problems.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  4. #4
    JPC Senior Member
    Join Date
    Feb 2003
    Posts
    57

    Thumbs up Thanks.

    Thanks Jason. That works like a charm. I was concerned about somebody finding and running the script so moving it out of public_html was a great idea. Not that the world would have ended if somebody ran the script just to be a jerk, but I didn't even want to give them the opportunity to hack around.

    And thanks for explaining some of the perl to me, that clarifies a few things.

    The only thing I noticed is that it doesn't email me that the job was run. Not needed or wanted at all in this case, but just wondering why it doesn't. It's possible I may want to have that for a different cron job in the future.
    Does the " > dev/null" at the end of the command kill the email notice?

    Thanks again for your help.
    Jeff

  5. #5
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Yes, the >/dev/null redirects the output of the script to /dev/null, also known as the Unix blackhole. Anything you send to /dev/null just simply disappears.

    If you remove the >/dev/null you'll get an email with the output of the script sent to your default email account [cpanelusername@yourdomain.com]. (Since your script doesn't have any output you'll just get what amounts to a status report.)

    You can also redirect the output to a file if, for example, you wanted to keep a log of the script running. To do that change >/dev/null to >>/home/username/somefile.txt (note the >>--that tells the server to append the new info to the end of what's already there. If you used > it would overwrite it.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  6. #6
    JPC Member
    Join Date
    Nov 2002
    Posts
    1

    setting up cron job to refresh rss.xml file

    Jason, I see how you helped someone else so I'm wondering if you can help me as well.

    I'm setting up an RSS feed on my website and all is working except I don't know how to set up a cron job so the xml file updates daily on the days new articles are posted to the website. I don't post new articles every day.

    The xml file is here:
    http://www.childrencomefirst.com/rss.xml

    I've used that URL to set up an RSS feed that is now showing in my blog and also on MyYahoo but don't know how to make the file refresh itself. I went to my control panel and thought I'd set things up right but immediately afterwards I received about 15-20 emails all saying the same thing:

    -----Original Message-----
    From: Cron Daemon [mailto:root@enterprise.nocdirect.com]
    Sent: Monday, November 05, 2007 10:15 PM
    To: omgary@childrencomefirst.com
    Subject: Cron <children@enterprise> publishcron.cgi

    /bin/sh: publishcron.cgi: command not found

    I then submitted a support ticket to JaguarPC asking if there was a tutorial at JaguarPC that would tell me what to do and tech support wrote back "It is a general Linux utility that can easily be found on the google." --- basically telling me to google the answer.

    I tried googling "jaguarpc set up cron job" and landed on this thread in the forums.

    Would love to know how to do this as I've got another 12 sites JaguarPC hosts for me that also want RSS feeds set up.

  7. #7
    Jag Veteran EuroNut's Avatar
    Join Date
    Aug 2007
    Location
    UK
    Posts
    529
    Quote Originally Posted by ogary View Post
    I've used that URL to set up an RSS feed that is now showing in my blog and also on MyYahoo but don't know how to make the file refresh itself.
    RSS feeds for blogs generally update themselves - As you add an entry to a blog it appears in the site and the RSS feed at the same time. Try adding a new blog entry and then looking at your RSS feed.

    As I see it, you don't need any sort of cron job for this!
    EuroNut (The mad Brit)
    If it ain't broke, don't ping it...

  8. #8
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    ogary,

    Cron can't find the update script because you need to provide a full path name to it. Where is the script located within your site? Also, how does the developer of the script recommend you run the update script? Since the script has a .cgi extension I'll assume that it is expected to be run from a URL, but I'll provide an example of how to do it the "normal" way via the server's filesystem as well.

    First, make sure that the publishcron.cgi is executable. You can do this through ssh (command line), but if you are using an FTP client to upload your content that client probably provides a GUI interface to do it as well. At minimum you need to give "user" read, write, and execute permissions (chmod 700). Due to JPC's setup you shouldn't need to set any permissions for "group" or "all/world," but most documentation will tell you to set chmod 755 (full permission for user, read and execute permission for group and all/world). If you've already done it won't hurt anything to keep it this way.

    Next, log in to cPanel and find the "Cron Jobs" link (under Tools). Then choose "standard" as it is an easier interface to use. In the minutes, hours, etc. fields set up when you want the script to run.

    Cron will run your script every minute of every day unless you tell it otherwise (and you absolutely DO NOT want to run it every minute of every day). Setting a value for minutes means that the script will run on that minute each hour (if you chose 5, for example, the script will run at 12:05, 1:05, 2:05,...). Likewise hours allows you to limit which hours of the day the script runs (using "military" time, so 1:00 pm would be 13), which days of the month the script runs, days of the month the script runs, and even which months of the year. So, if you want to run the script every morning at 1:06 am, chose minutes=6, hours=1, days=every day, months=every month, weekdays=every weekday.

    For the command, assuming your script is intended to to be run as a URL, try using this syntax for the command to run:
    Code:
    wget http://www.yoursite.com/cgi-bin/publishcron.cgi >/dev/null
    Of course you need to change the URL to reflect the actual location of your publishcron.cgi file.

    If the above doesn't work, try using this as your command:
    Code:
    /home/USER/public_html/cgi-bin/publishcron.cgi >/dev/null
    Change USER to your cPanel user name and again, adjust the path as appropriate.

    I hope this helps. Please repost to let us know how it works.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •