cancel
Showing results for 
Search instead for 
Did you mean: 

appending hostname to filename

Jeff Hargiss
Advisor

appending hostname to filename

trying to append the hostname to a redirect of stndout.

i want to do file.hostname

i get file.

here is my script:
#!bin/sh
HOST= /bin/hostname

utility > file.$HOST

i have tried ( " ` ' { in various combinations without success.

i am probably not using the right combination (or maybe needing spaces)

thoughts?

thanks!
illegitmus non corrundum
5 REPLIES
Hasan Atasoy
Honored Contributor

Re: appending hostname to filename

#!bin/sh

HOST=`/bin/hostname`

utility > file.$HOST



Hasan.
James R. Ferguson
Acclaimed Contributor

Re: appending hostname to filename

Hi Jeff:

#!/usr/bin/sh
HOST=$(hostname)
./utility > file.${HOST}


Regards!

...JRF...
Jeff Hargiss
Advisor

Re: appending hostname to filename

ok, here is how i got it working from the suggestions given {THANKS!}

#!/usr/bin/sh <--- added /usr/

HOST=$(hostname)

utility >file.$HOST <-- did not need ( {

thanks everyone!
illegitmus non corrundum
Jeff Hargiss
Advisor

Re: appending hostname to filename

solved, thanks for the help!
illegitmus non corrundum
James R. Ferguson
Acclaimed Contributor

Re: appending hostname to filename

Hi (again) Jeff:

> #!/usr/bin/sh <--- added /usr/

Which had nothing to do with your problem, but is the appropriate path.

> utility >file.$HOST <-- did not need ( {

Which with the curly braces is the _preferred_ and/or _correct_ way to dereference shell variables. It tells the shell exactly where the variable name begins and ends...

Regards!

...JRF...