Re: Managing variables -very important (233 Views)
Reply
Esteemed Contributor
Marco_ALT
Posts: 633
Registered: ‎03-24-2007
Message 1 of 14 (233 Views)

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


Honored Contributor
Duncan Edmonstone
Posts: 5,684
Registered: ‎08-05-2000
Message 2 of 14 (233 Views)

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
Marco_ALT
Posts: 633
Registered: ‎03-24-2007
Message 3 of 14 (233 Views)

Re: Managing variables -very important

Hello


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


thanks
Honored Contributor
Duncan Edmonstone
Posts: 5,684
Registered: ‎08-05-2000
Message 4 of 14 (233 Views)

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
Laurent Menase
Posts: 1,079
Registered: ‎11-06-2003
Message 5 of 14 (233 Views)

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
Marco_ALT
Posts: 633
Registered: ‎03-24-2007
Message 6 of 14 (233 Views)

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
Hakki Aydin Ucar
Posts: 1,314
Registered: ‎08-16-2006
Message 7 of 14 (233 Views)

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
Dennis Handly
Posts: 25,281
Registered: ‎03-06-2006
Message 8 of 14 (233 Views)

Re: Managing variables -very important

>but I got this error msg

Where? On stderr or in tmp/myfile.txt?
Honored Contributor
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 9 of 14 (233 Views)

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
Marco_ALT
Posts: 633
Registered: ‎03-24-2007
Message 10 of 14 (233 Views)

Re: Managing variables -very important

i changed it to

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

but still the same error
!!!!
plz advise
Acclaimed Contributor
Dennis Handly
Posts: 25,281
Registered: ‎03-06-2006
Message 11 of 14 (233 Views)

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
Dennis Handly
Posts: 25,281
Registered: ‎03-06-2006
Message 12 of 14 (233 Views)

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
Marco_ALT
Posts: 633
Registered: ‎03-24-2007
Message 13 of 14 (233 Views)

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
Acclaimed Contributor
Dennis Handly
Posts: 25,281
Registered: ‎03-06-2006
Message 14 of 14 (233 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.