BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Managing variables -very important

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
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
Esteemed Contributor

Re: Managing variables -very important

Hello


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


thanks
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
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

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
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 ?
Acclaimed Contributor

Re: Managing variables -very important

>but I got this error msg

Where? On stderr or in tmp/myfile.txt?
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
Esteemed Contributor

Re: Managing variables -very important

i changed it to

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

but still the same error
!!!!
plz advise
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.
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
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
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