Question about a cron job

Discussion in 'OT Technology' started by k2737, Sep 30, 2006.

  1. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    I have a cron job setup to run a script that parses through are maillogs and emails me the results. It also runs another script that uploads the results to a shared drive. Now when I run the script from the command line it works fine, but when cron runs it, it doesn't send the email...but they files do get uploaded. Any reason why email wouldn't work from cron? :o
     
  2. RaginBajin

    RaginBajin Have you punched a donkey today?

    Joined:
    Dec 24, 2001
    Messages:
    8,740
    Likes Received:
    0
    Location:
    NoVA
    It is probably because of the shell that the cron is running under. If you run a bash shell normally then put a '/bin/bash' in front of the cron command that you are trying to run. That will make sure that you run it in bash.

    Give that a shot.
     
  3. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Alright I will check when I go into work tomorrow...I can't remember if I had that there or not. Also I will post the script itself...maybe I have some typo? There are no errors in the logs though...
     
  4. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,436
    Likes Received:
    11
    Ensure the environmentals are getting sourced within your script or in the cron job. Also redirect the output to a log file, or check the users mail, and check the cron log to see if it ran successfully.
     
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Dammit. I posted about checking that $PATH was setup properly for cron, and if you were using fully qualified paths: mail or /bin/mail?
     
  6. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Is crons log /var/log/messages? Cause thats where I looked for errors before :hsd:
     
  7. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    I am not using the full path...should I?

    EDIT: I guess if the evironment variables are correct it doesn't matter right?
     
  8. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Use the full path in order to avoid environmental variable problems. But no, if the environment is setup it shouldn't matter.
     
  9. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,436
    Likes Received:
    11
    No. There's a specific log for cron.

    Depending on what OS you're using, but it seems like you're using a flavor of linux, so it's /var/log/cron

    At this point, it doesn't matter if your environment is correct or not. You need to ensure it is sourced within the cron job line or within your script.

    For instance, let's just say all over your ENV is in ~/.bash_profile

    You need to source that within your script.

    Put that before all of your variables or right after your shell declaration:

    #!/bin/bash

    . /home/app_user/.bash_profile

    But before we go through all of that, to troubleshoot set -x within the script or make your cron look like this

    0 20 * * * /bin/bash -x /path/of/script > /tmp/output.out 2>&1

    So when it's supposed to run you see what fails or what doesn't fail in the /tmp/outout.out output.
     
    Last edited: Oct 1, 2006
  10. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    :bowdown: I will try that tomorrow.
     

Share This Page