Perl Scripting

Hi,
I want to use the mailx command or sendmail command in perl script.
I am trying this one and getting error:

system "mailx -s \"Test mail\" $ar1";

Error:

The flags you gave are used only when sending mail.

Vaibhav,

Try this instead:

 open \(MAIL,"|mailx -s <subject> <email addresses>"\);
 print MAIL "Mail line 1\\n";
 print MAIL "Mail line 2\\n";
 ...
 close \(MAIL\);

Greg

You could use the pipe open() of Perl as showed by Greg.
(see perldoc perlopentut, perldoc perlipc)
However, if you cannot trust the caller's input I would either
do a forking open with untainting in the child's block,
or rather use modules like Mail::Send or Mail::Mailer etc.

Hi Greg 10X,
your advice worked regarding the perl script. :slight_smile:

Hi All,

How can i use "echo" command in perl?

Let suppose i set one variable $usr_info = abc /def/ghi/abc

now want get the out put /def/ghi/abc in variable my_path using command like this

$my_path = `echo $usr_info | cut -f2 -d" "`

but i am getting error related to "|" "pipe" when i run the script.

Can't reproduce.

Maybe post the relevant lines and the exact output (inc. error message)?

You are obviously mixing shell and Perl variables here.
Generally you should avoid this mixture because Perl is powerful enough
to get rid of all shell escapes, and Perl has built-ins of almost all Unix syscalls
which render them completely redundant.
Not only degrades this the performance of your Perl program
(though this is seldom an issue for the quick and dirty hack),
but it also makes your programs more insecure,
which indeed is relevant for e.g. CGIs or server programs.
(n.b. if you can afford the time you should read perldoc perlsec )

But if you are reluctant to rewrite your shell script wrapper into your Perl code
then you could either pass shell variables to the called Perl script
e.g.

$ (user_info="abc /def/ghi/abc"; perl -le '$my_path=$ARGV[1];print $my_path' $user_info)
/def/ghi/abc

or you could access the shell variables via the %ENV hash,
provided you export them in your shell wrapper script
e.g.

$ (user_info="abc /def/ghi/abc" perl -le '$my_path=$ENV{user_info};print $my_path' $user_info)
abc /def/ghi/abc

Oops, I made a flaw.
Of course you would further need to split or pattern match the value of $ENV{user_info}

$ (user_info="abc /def/ghi/abc" perl -le '$my_path=(split/\s+/,$ENV{user_info})[1];print $my_path' $user_info)
/def/ghi/abc

Hi There,
I am getting a vieared problem while building my code: problem is as follow:
/usr/lib/dld.sl: Call to mmap() failed - TEXT /oravl01/oracle/9.2.0.7/lib32/libclntsh.sl.9.0
/usr/lib/dld.sl: Not enough space
Abort (core dumped)
any body have idea how to resolve it?

Hi There,

I am writing a perl script in which i want to do something like this:

for $line ( `cat /etc/passwd | grep 'sbcuser'`){
print "1. Hi $line \n";
$usr=`cut -f1 -d':' $line`;
$fs=`cut -f6 -d':' $line | xargs dirname`;
%user=( "$usr" => $fs);
}

but i am getting error while executing this peace of code.

Any idea what i am missing?

#!/usr/bin/perl
open FH , "/etc/passwd" ;
while( <FH> ){
if( /^sbcuser/ )
{
print "1. Hi $_ \n";
@F=split /:/;
$usr=$F[0];
$F[5] =~ s,/[^/]+$,,;
$fs=$F[5];
%user=( "$usr" => $fs);
}
}