Unix administration - Why I can not print out $HOST inside cron job

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > January 2007 > Why I can not print out $HOST inside cron job





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Why I can not print out $HOST inside cron job
linq936@hotmail.com

2007-01-06, 8:01 pm

Hi,
I set up my crontab like this,

USER=linq
USERNAME=linq
HOME=/home/linq
UID=linq
00 16 * * * source /home/linq/start.sh > /home/linq/start.log 2>&1


And the first 3 lines of ~/start.sh are,

echo HOST is $HOST
echo
echo


But when I check out ~/start.log, it has these on the top:

HOST is


If I run command, "echo $HOST", I do see it works.

Any suggestion why it is like this?

Bit Twister

2007-01-06, 8:01 pm

On 2 Jan 2007 08:56:04 -0800, linq936@hotmail.com wrote:

> Any suggestion why it is like this?


Cron jobs do not run through the same setup as logins.

in your cron job try

HOST=$((hostname))

above your echo statement.
linq936@hotmail.com

2007-01-06, 8:01 pm


Bit Twister wrote:
> On 2 Jan 2007 08:56:04 -0800, linq936@hotmail.com wrote:
>
>
> Cron jobs do not run through the same setup as logins.
>
> in your cron job try
>
> HOST=$((hostname))
>
> above your echo statement.


Thanks for your suggestion, but here is what I see:

I have the following on the top of the BASH script which is called in
cron job:
HOST=$((hostname))
echo HOST is $HOST
echo hostname is $hostname
echo

But what I see is,
HOST is 0
hostname is


Any suggestion?

Erik Max Francis

2007-01-06, 8:01 pm

linq936@hotmail.com wrote:

> I have the following on the top of the BASH script which is called in
> cron job:
> HOST=$((hostname))
> echo HOST is $HOST
> echo hostname is $hostname
> echo
>
> But what I see is,
> HOST is 0
> hostname is


He meant

HOST=$(hostname)

or, more portably,

HOST=`hostname`

hostname is a command, the above statements assign its output to the
environment variable HOST, which is what you want. Your printing of
$hostname is meaningless.
--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
They have rights who dare defend them.
-- Roger Baldwin
Kenan Kalajdzic

2007-01-06, 8:01 pm

linq936@hotmail.com wrote:
>
> Bit Twister wrote:
>
> Thanks for your suggestion, but here is what I see:
>
> I have the following on the top of the BASH script which is called in
> cron job:
> HOST=$((hostname))


The above line should be:

HOST=$(hostname)

> echo HOST is $HOST
> echo hostname is $hostname
> echo
>
> ...
>


--
Kenan Kalajdzic
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com