Using crontab to run a .csh script as ROOT

Posted on 2004-11-03
Last Modified: 2013-12-16

I'm relatively new to linux and I'm trying to set up a cronjob which runs a .csh script at a given time each day.  The script invokes a program called 'PTA'.  I can get the script to start ok as a cronjob but it does not run to completion.  At /var/spool/mail/root I receive a message telling me that the PTAHOME variable is not set.  

The thing is that I HAVE set this variable in both the .bashrc and .cshrc files and if I run the script from the command line it executes perfectly with no mention of the PTAHOME variable.  Has anyone got any suggestions as to what might be going wrong?

Cheers in advance,

Question by:travisbickle34
    LVL 17

    Expert Comment

    Simply set the variables in your script - cron runs with a different envirnment. So in the script which runs  PTA just do an  export PTAHOME= MYVAR (or whatever the csh equiv is).

    Author Comment

    I have checked /etc/crontab and the cronjob is actually set to run in a the scripts in a bash shell.

    However, when I include the PTAHOME definition in the cron file like this:

    export PTAHOME=/paracel/paracel/pta/pta
    48 11 * * * /export/home/penlims/Arragen.wrap
    41 15 * * * /export/home/penlims/PipelineSummary.csh

    I get this error message:

    "Pipeline.cron":8: bad minute
    errors in crontab file, can't install.

    LVL 2

    Expert Comment

    I think ownesleftfoot meant that you should set the variable in your *script* not in the crontab itself.


    Author Comment

    The fact that the script will run perfectly from the command line would suggest that the script is ok though, would it not?  Also, my wrapper script does contain a precautionary PTAHOME definition, although to be honest I don't think it is used.
    LVL 17

    Accepted Solution

    Nah, I didnt mean put it in the crontab - put it in the script you are trying to run. If you are using cron to run pta directly, use a script instead ie call it runpta  make it executable chmod +x runpta and make sure it contains the variables you want and the command to run your program - ie

    export PTAHOME=paracel/paracel/pta/pta

    then in cron you would have

    48 11 *** /path-to-runpta/runpta

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now