Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable values to shell from perl 1

Status
Not open for further replies.

dmazzini

Programmer
Jan 20, 2004
480
US
Embedded Shell from Perl Script.

Hi experts

I have a shell routine to send mails from unix system..I would like to reuse it, passing perl variables to to the routine. However I am getting some errors
I can't get the value of the variables into the shell routine...

Here I have posted two routines.

1. It is working:

#sending.pl

$shell_in = <<'IN';

file_1=file1
file_2=file2
file_3=file3

SUBJ="Send mail from Unix with file attachments"
TO=name@domain.com
CC=name2@domain.com,name3@domain.com
(
cat << !
To : ${TO}
Subject : ${SUBJ}
Cc : ${CC}
!

cat << !
IT WORKS
This sample E-mail message demonstrates how one can attach
files when sending messages with the Unix sendmail utility.
!

uuencode ${file_1} ${file_1}
uuencode ${file_2} ${file_2}
uuencode ${file_3} ${file_3}
!

) | sendmail -v ${TO} ${CC}


IN


$shell_out = `$shell_in`;


2. Passing some arguments from perl: I have the variables $file_1,$file_2,$file_3,$email_subject
$email_to_addrs, email_cc_addrs. If I print the variables in the routine I can see the values..The problem
is that I can not capture this variables..



sub send_mail {

$shell_in = <<'IN';

file_1=${$file1}
file_2=${$file2}
file_3=${$file3}

SUBJ=${$email_subject}
TO=${$email_to_addrs}
CC=${$email_cc_addrs}
(
cat << !
To : ${TO}
Subject : ${SUBJ}
Cc : ${CC}
!

cat << !
IT DOES NOT WORK
This sample E-mail message demonstrates how one can attach
files when sending messages with the Unix sendmail utility.
!

uuencode ${file_1} ${file_1}
uuencode ${file_2} ${file_2}
uuencode ${file_3} ${file_3}
!

) | sendmail -v ${TO} ${CC}


IN


$shell_out = `$shell_in`;

}

Any help will be very appreciated.

I have other routines for sending mail from unix system that works very well, but I want to use it for learning purposes.


Thanks in advance!
 
You appear to be referencing scalar values, rather than using the literal scalar values. Such that:

Code:
file_1=${$file1}
SUBJ=${$email_subject}

should be

Code:
file_1=$file1
SUBJ="$email_subject"

Barbie
Leader of Birmingham Perl Mongers
 
I have tried your code:

sub send_mail {

$file_1=$file_1;
$file_2=$file_2;
$file_3=$file_3;
$SUBJ=$email_subject;
$TO=$email_to_addrs;
$CC=$email_cc_addrs;

$shell_in = <<'IN';
(
cat << !
To : ${TO}
Subject : ${SUBJ}
Cc : ${CC}
!

cat << !
IT DOES NOT WORK
This sample E-mail message demonstrates how one can attach
files when sending messages with the Unix sendmail utility.
!

uuencode ${file_1} ${file_1}
uuencode ${file_2} ${file_2}
uuencode ${file_3} ${file_3}
!

) | sendmail -v ${TO} ${CC}


IN

print "$shell_in\n";
#$shell_out = '$shell_in`;

}

#########################################################



The ouput from the command print "$shell_in\n";

(
cat << !
To : ${TO}
Subject : ${SUBJ}
Cc : ${CC}
!

cat << !
HOPE THIS WORKS
This sample E-mail message demonstrates how one can attach
files when sending messages with the Unix sendmail utility.
!

uuencode ${file_1} ${file_1}
uuencode ${file_2} ${file_2}
uuencode ${file_3} ${file_3}
!

) | sendmail -v ${TO} ${CC}


So, it looks like I am not passing the variables correctly to the shell routine...

Any advice!!!!





 
Ah, I see a light .... it took a while, but I finally spotted it:

This:
Code:
$shell_in = <<'IN';

Should be:
Code:
$shell_in = <<"IN";

The single quotes around the IN prevent interpolation on any variable like strings inside.

Barbie
Leader of Birmingham Perl Mongers
 
It works very well! Thanks OK!

Yesterday afternoon I was trying to find what I was doing wrong!!!

Thanks mate! Have a good weekend!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top