LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-15-2006, 12:34 PM   #1
Alfar
LQ Newbie
 
Registered: Dec 2006
Posts: 15

Rep: Reputation: 0
cron jobs environment variables


Hello,

My system is a Debian Sarge. The problem is that no matter what i do cron executes with the same environment setting every time.

SHELL=/bin/sh
PATH=/usr/bin:/bin
_=/usr/bin/env
PWD=/home/username
LANG=en_GB
HOME=/home/username
SHLVL=2
LANGUAGE=en_GB:en_US:en_GB:en
LOGNAME=username

It completely ignores ~/.bash_profile /etc/profile /etc/bash.bashrc

My shell script is linked to bash i.e. /bin/sh -> bash

I also tried editing the /etc/crontab to add the environment settings i wanted but it didnt work.

The aim was to use keychain to automate backup but although the scripts work fine from login they dont from cron because of the missing variables SSH_...

Nothing was mentioned about this in the documentation I followed and although many people have had similar problems the information is patchy.

The main question is,
Where to change environment variables for cron jobs?

Thank you for reading this post

Last edited by Alfar; 12-15-2006 at 12:49 PM.
 
Old 12-15-2006, 12:54 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
You should be able to set most environment settings in the actual crontab. And don't edit the /etc/crontab, add them by doing: crontab -e
 
Old 12-15-2006, 01:02 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Globally (for all users), cron execution environment may be changed by editing the /etc/crontab file. See the crontab manual page in section 5 for more information:
Code:
man 5 crontab
For executing a specific job with the full environment from the ~/.bashrc file, I find using a wrapper script is a useful approach.
 
Old 12-15-2006, 01:17 PM   #4
Alfar
LQ Newbie
 
Registered: Dec 2006
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by trickykid
You should be able to set most environment settings in the actual crontab. And don't edit the /etc/crontab, add them by doing: crontab -e
Thank you both for the quick responce.

However, i am still a bit confused with regards to keychain. I compared two howtos (below) on how to install keychain and none of them mentioned that i must add ssh-agent environment variables to the crontab -e or using a wrapper script.

http://www.debian-administration.org/articles/209

http://www-128.ibm.com/developerwork...9Backup#N10050

Are they just out of date?
 
Old 12-15-2006, 01:47 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
When setting up public key authentication, you can choose to add a passphrase to access the keypair. If you don't do this, you won't need to use the ssh-agent.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Jobs christo512 Linux - Software 1 02-09-2006 09:19 AM
Cron Losing Environment Variables? SteveT Fedora 1 12-24-2005 08:37 AM
Cron Jobs XaViaR Linux - General 1 06-23-2005 06:57 PM
CRON Jobs scottpioso Linux - Software 63 11-28-2003 06:45 PM
cron jobs Zyanid Linux - Software 0 08-27-2002 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration