LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2012, 11:47 AM   #1
Jon Blanchard
LQ Newbie
 
Registered: Feb 2012
Location: Franklin, TN
Distribution: Linux, AIX
Posts: 6

Rep: Reputation: Disabled
Cron job is not recognizing environment variables


This is for Red Hat Enterprise Linux running bash 3.2.25(1).

I created a .sh file to collect thread statistics for the application that the server was built for. The shell file is supposed to read the value of one key environment variable, $HCIROOT, at the beginning; it isn't, so the value of all derived vars are missing what should be there. The remainder of the shell script runs as it should, but without accomplishing anything.

The script file references the environment var using $<varname>, which I saw in another job file that runs fine every night. Is there another method that I should be using?

The HCIROOT environment var is set when the server is booted (once per year), so what do I need to do get the shell script to use it?

Thanks in advance for your response.
 
Old 02-15-2012, 12:13 PM   #2
ShadowCat8
Member
 
Registered: Nov 2004
Location: Arcadia, CA
Distribution: Gentoo, Arch, (RedHat4.x-9.x, FedoraCore 1.x-4.x, Debian Potato-Sarge, LFS 6.0, etc.)
Posts: 220

Rep: Reputation: 46
Greetings,

Okay, now to start off, let me ask you: Where is the $HCIROOT variable being set from and do you see it in the output when you do the env command?

HTH. Let us know.
 
Old 02-16-2012, 10:53 PM   #3
Jon Blanchard
LQ Newbie
 
Registered: Feb 2012
Location: Franklin, TN
Distribution: Linux, AIX
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hmmm...that is a great question.

This is a dedicated interface engine server, so the HCIROOT var should be set at server startup, based on the server startup file. The var does appear when I type env or set.

There is also a .profile in the /home/hci directory, which I assume is run whenever I log in as hci. The HCIROOT var is not set there.
 
Old 02-17-2012, 12:12 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Quote:
the HCIROOT var should be set at server startup
That would be in a different process env to cron job.
If you want it avail to other processes, it needs to be set eg in /etc/profile, or maybe even in a file.
Each process runs in its own env in *nix; there's no 'global' env as such, although you can 'export' vars down a process tree.
See various references to 'export' here http://linux.die.net/man/1/bash
 
Old 02-17-2012, 11:27 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There is a fair chance that the variable is defined in a file containing a line something like:
Code:
HCIROOT='some value'
A common idiom in Linux, especially startup scripting, is to use such configuration files by sourcing them:
Code:
#! /bin/bash
. /etc/your_hciroot_config
If you can locate a file that contains such a format, your cron job script can use the same method to set the value of $HCIROOT.

--- rod.
 
Old 02-17-2012, 12:06 PM   #6
ShadowCat8
Member
 
Registered: Nov 2004
Location: Arcadia, CA
Distribution: Gentoo, Arch, (RedHat4.x-9.x, FedoraCore 1.x-4.x, Debian Potato-Sarge, LFS 6.0, etc.)
Posts: 220

Rep: Reputation: 46
Quote:
Originally Posted by theNbomr View Post
There is a fair chance that the variable is defined in a file containing a line something like:
Code:
HCIROOT='some value'
A common idiom in Linux, especially startup scripting, is to use such configuration files by sourcing them:
Code:
#! /bin/bash
. /etc/your_hciroot_config
If you can locate a file that contains such a format, your cron job script can use the same method to set the value of $HCIROOT.
Yep, that's right. That is kind of where I was headed with my questions. If you haven't found the file that is setting the variable yet, try this:
Code:
 ~ $ grep -r HCIROOT /etc/*
and see what comes back. If nothing comes back at all, then, while logged in as 'hci', try this:
Code:
 ~ $ grep -r HCIROOT ~/.[A-z]*
And see if it is being set somewhere else in the home directory.

HTH. Let us know.

Last edited by ShadowCat8; 02-17-2012 at 12:10 PM.
 
Old 02-17-2012, 10:50 PM   #7
Jon Blanchard
LQ Newbie
 
Registered: Feb 2012
Location: Franklin, TN
Distribution: Linux, AIX
Posts: 6

Original Poster
Rep: Reputation: Disabled
The result of
Code:
grep -r HCIROOT /etc/*
was a mass quantity of "Permission denied" and "No such device or address" restrictions on every file that grep tried to search.

The result of
Code:
grep -r HCIROOT ~/.[A-z]*
was a list of references to HCIROOT in the .bash_history file. The birth of this variable is quite the mystery.

Reading theNbomr's statement about the common idiom in Linux gave me the idea to source the .profile from within my getstats2.sh script, instead of sourcing it in the crontab file. Both files are in /home/hci, at least for now. I also decided to manually create the HCIROOT var since, on this engine product, the var is always set to
Code:
$CL_INSTALL_DIR/integrator
and the CL_INSTALL_DIR var is set in /home/hci/.profile.

Let me know what you think. And thanks for all your suggestions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron jobs environment variables Alfar Linux - General 4 12-15-2006 02:47 PM
Cron Losing Environment Variables? SteveT Fedora 1 12-24-2005 09:37 AM
changing variables from background job bobwall Programming 2 06-18-2005 03:28 PM


All times are GMT -5. The time now is 02:27 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration