Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2013
    Posts
    5

    Question Unanswered: tcsh set environment variables in cron

    Hi, I have a tcsh script that sets environment variables for another perl script to use. The script runs fine when I source the shell script of the extension .src and the perl script could read the environment variables as well. However, when I execute these two scripts in cron, the environment variable could not be found. Can I know what must I do to make cron sets the environment in tcsh? I've set the crontab shell to be on tcsh but it still fails to set the other environment variables.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    See these:
    Csh Programming Considered Harmful

    http://www.grymoire.com/Unix/CshTop10.txt
    Csh <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
    Good luck.
    However, the most likely cause of your problem is that the PATH and environment is different between your interactive session and the cron session.
    Add 'env >/tmp/mycron.log' to the script and compare the results to your interactive session.

  3. #3
    Join Date
    Feb 2006
    Posts
    173
    Provided Answers: 1
    I agree with kitaman, Check out this info(PATH HOWTO: Shells) and setup your environment in the appropriate file so that it will get setup for interactive or non-interactive sessions.

  4. #4
    Join Date
    Mar 2013
    Posts
    5
    No luck...I've set the path and the shell level to be the same as my scripts but cron just could not detect the environment variables set...any other suggestions?

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Can we see the code, and the error messages if any?

  6. #6
    Join Date
    Mar 2013
    Posts
    5
    Everything is fine when I source the file...However, when my perl script wishes to access the environment variable, this is the error message i get...
    "DISK: Undefined variable."

    this is how i set my environment variable
    #!/bin/tcsh
    setenv DISK /c/disks/name

    and this is the perl script that I use to access the variables
    #!/usr/bin/perl
    print "DISK: \$DISK";


    I even tried to print all the environment variables in cron by the script below
    foreach my $key (sort keys %ENV) {
    print "\$ENV{$key} = $ENV{$key}\n";
    }


    but I cant seem to get the DISK environment variable...

  7. #7
    Join Date
    Feb 2006
    Posts
    173
    Provided Answers: 1
    This works in tcsh version(tcsh 6.12.00):
    Code:
    #!/usr/bin/tcsh
    # Script:  test_tcsh.sh
    setenv DISK /c/disks/name
    perl -e 'print "DISK: $ENV{DISK}\n";'
    perl -e 'foreach $key (keys %ENV) { print "$key is $ENV{$key}\n"; }'

  8. #8
    Join Date
    Mar 2013
    Posts
    5
    I've found the solution already...I just call the perl script from the tcsh script and everything works...thank you for all the help..

Posting Permissions

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