LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2012, 08:33 AM   #1
Boomn4x4
LQ Newbie
 
Registered: Feb 2009
Posts: 8

Rep: Reputation: 0
PERL script not seeing env vars when run by cron


I have a perl script that works fine when I run it from the command line, but now that I'm running it (as root) from cron, it isn't picking up my environment variables.

my $host = $ENV{HOST}
print "Host = $host\n";

when run from cron it results in
"Host ="

but when I run it from the shell,
"Host = myhostname"
 
Old 05-04-2012, 09:09 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
probably HOSTNAME will work.
 
Old 05-04-2012, 12:22 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Boomn4x4 View Post
I have a perl script that works fine when I run it from the command line, but now that I'm running it (as root) from cron, it isn't picking up my environment variables.

my $host = $ENV{HOST}
print "Host = $host\n";

when run from cron it results in
"Host ="

but when I run it from the shell,
"Host = myhostname"
(Re)read 'man cron' - I vaguely remember 'cron' deals with environment in a special way.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading env into bash script called by cron grob115 Programming 1 03-18-2010 11:35 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Inserting ENV. VARS. for all of Linux to use Last Attacker Linux - General 3 02-01-2007 01:57 PM
env vars on Slackware 10 lvella Linux - General 1 11-01-2004 04:55 PM
init on boot programs that need env vars The_Spider Linux - General 3 04-29-2004 07:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 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
Open Source Consulting | Domain Registration