Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 608047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:25:21+00:00 2026-05-13T17:25:21+00:00

I have a crontab running every hour. The user running it has environment variabless

  • 0

I have a crontab running every hour. The user running it has environment variabless in the .bash_profile that work when the user runs the job from the terminal, however, obviously these don’t get picked up by crontab when it runs.

I’ve tried setting them in .profile and .bashrc but they still don’t seem to get picked up. Does anyone know where I can put environment vars that crontab can pick up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:25:21+00:00Added an answer on May 13, 2026 at 5:25 pm

    Have ‘cron’ run a shell script that sets the environment before running the command.

    Always.

    #   @(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $
    #   Crontab file for Home Directory for Jonathan Leffler (JL)
    #-----------------------------------------------------------------------------
    #Min     Hour    Day     Month   Weekday Command
    #-----------------------------------------------------------------------------
    0        *       *       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/hourly
    1        1       *       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/daily
    23       1       *       *       1-5     /usr/bin/ksh /work1/jleffler/bin/Cron/weekday
    2        3       *       *       0       /usr/bin/ksh /work1/jleffler/bin/Cron/weekly
    21       3       1       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/monthly
    

    The scripts in ~/bin/Cron are all links to a single script, ‘runcron’, which looks like:

    :       "$Id: runcron.sh,v 2.1 2001/02/27 00:53:22 jleffler Exp $"
    #
    #       Commands to be performed by Cron (no debugging options)
    
    #       Set environment -- not done by cron (usually switches HOME)
    . $HOME/.cronfile
    
    base=`basename $0`
    cmd=${REAL_HOME:-/real/home}/bin/$base
    
    if [ ! -x $cmd ]
    then cmd=${HOME}/bin/$base
    fi
    
    exec $cmd ${@:+"$@"}
    

    (Written using an older coding standard – nowadays, I’d use a shebang ‘#!’ at the start.)

    The ‘~/.cronfile’ is a variation on my profile for use by cron – rigorously non-interactive and no echoing for the sake of being noisy. You could arrange to execute the .profile and so on instead. (The REAL_HOME stuff is an artefact of my environment – you can pretend it is the same as $HOME.)

    So, this code reads the appropriate environment and then executes the non-Cron version of the command from my home directory. So, for example, my ‘weekday’ command looks like:

    :       "@(#)$Id: weekday.sh,v 1.10 2007/09/17 02:42:03 jleffler Exp $"
    #
    #       Commands to be done each weekday
    
    # Update ICSCOPE
    n.updics
    

    The ‘daily’ command is simpler:

    :       "@(#)$Id: daily.sh,v 1.5 1997/06/02 22:04:21 johnl Exp $"
    #
    #       Commands to be done daily
    
    # Nothing -- most things are done on weekdays only
    
    exit 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.