Why I can not print out $HOST inside cron job
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Why I can not print out $HOST inside cron job




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:01 AM

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?






[ Post a follow-up to this message ]



    Re: Why I can not print out $HOST inside cron job  
Bit Twister


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:01 AM

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.





[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:01 AM


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?






[ Post a follow-up to this message ]



    Re: Why I can not print out $HOST inside cron job  
Erik Max Francis


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:01 AM

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





[ Post a follow-up to this message ]



    Re: Why I can not print out $HOST inside cron job  
Kenan Kalajdzic


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:01 AM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:23 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register