Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Managing variables -very important

Marco_ALT
Esteemed Contributor

Managing variables -very important

Hello

I have an operations which give the output in a variable $out

I want to send this output by e-mail, so guys know that the job has been finished.

Simply, i need to write the variable $out to a file, after that i can send it by e-mail.

Can you please help with this?

thanks


13 REPLIES
Duncan Edmonstone
Honored Contributor

Re: Managing variables -very important

Why do you need to write the value to a file? Am I over-simplifying this?:

echo "Output of operation is <${out}>" | mailx -s "Output of operation" my.email@myaddress.com


Won't that do?

HTH

Duncan


HTH

Duncan
Marco_ALT
Esteemed Contributor

Re: Managing variables -very important

Hello


can i write this output to a .txt file or .csv file??


thanks
Duncan Edmonstone
Honored Contributor

Re: Managing variables -very important

Sure if you want:

echo ${out} > /tmp/myfile.txt

cat /tmp/myfile.txt | mailx -s "Output of operation" my.email@myaddress.com

To a CSV file??? what are you trying to put in comma delimited format??

Maybe you need tyo define your problem statement a bit further

HTH

Duncan

HTH

Duncan
Laurent Menase
Honored Contributor

Re: Managing variables -very important

do you man as an attachement?

mail myname@myaddr <Subject: fin de job
Content-Type: application/vnd.ms-excel;
name="t1.csv"
Content-Transfer-Encoding: 7bit

$out
.
EOF

Marco_ALT
Esteemed Contributor

Re: Managing variables -very important

Hello

i am trying to write the variable to that file using command

#echo ${out} > /tmp/myfile.txt
but i got this error msg

Result=ChannelExec;returnResult=ChannelExec;returnCode=-1.............................


what is the channedExec error and how i can solve it?

thanks
Hakki Aydin Ucar
Honored Contributor

Re: Managing variables -very important

it seems like a Java application error not HP-UX . Did you use a java code to get this output ?
Dennis Handly
Acclaimed Contributor

Re: Managing variables -very important

>but I got this error msg

Where? On stderr or in tmp/myfile.txt?
Matti_Kurkela
Honored Contributor

Re: Managing variables -very important

If your variable may contain spaces, semi-colons and/or other characters with a special meaning to the shell, put double quotes around it.

echo "${out}" > /tmp/myfile.txt

The semi-colon (;) ends one shell command and begins another. If your variable contains semi-colons and the variable expansion is not quoted, the first semi-colon will terminate the echo command and the rest of the variable content will be interpreted as shell command(s), most likely causing error messages.

MK
MK
Marco_ALT
Esteemed Contributor

Re: Managing variables -very important

i changed it to

echo "${TAP OUT}" > file02.txt;

but still the same error
!!!!
plz advise
Dennis Handly
Acclaimed Contributor

Re: Managing variables -very important

>MK: If your variable contains semi-colons and the variable expansion is not quoted, the first semi-colon will terminate the echo command

Not hardly, a real shell doesn't look for a ";" after variable expansion:
$ x="abc;def"
$ echo $x
abc;def

The reason you quote things is because you want to preserve the whitespace.
Dennis Handly
Acclaimed Contributor

Re: Managing variables -very important

>echo "${TAP OUT}" > file02.txt

You can't do that. You can't have spaces in a variable name. You would get:
ksh: "${TAP OUT}": bad substitution
Marco_ALT
Esteemed Contributor

Re: Managing variables -very important

when i substitute with the following

x="TAP OUT"
echo $x > file02.txt;

i received the e-mail contaning "TAP OUT" as the body!!

i need to subistitue with the variable value
ie $TAP OUT not the name char "tap out"

shall i do it like
x="${TAP OUT}"
echo $x.........
?
plz advise
Highlighted
Dennis Handly
Acclaimed Contributor

Re: Managing variables -very important

>I need to substitute with the variable value
ie $TAP OUT not the name char "tap out"

You can't have a variable with embedded spaces.

If you want to do variable "indirection":
$ x=9
$ y=10
$ z=x
$ eval echo \$$z
9