Email Attachment Script

Hello,

I created the following script but i'm trying to figure out why i keep getting an error.

#!/usr/bin/perl -w
use strict;
use warnings;

my $baseDir = '/export/home/omcadmin/bin';
my $attachment = "$baseDir/message.txt";

my $from = 'xxx@xxx.com';
my $to = 'xxx@xxx.com';
my $cc = 'xxx@xxx.com';
my $subj = 'Testing';
my $body = 'TEST';

my $cmd = "uuencode $attachment |mailx, '-s',$subj, '-c', $cc, $to, "-f$from"";
system ("$cmd");

The error i receive is:
email.pl: use: not found
email.pl: use: not found
email.pl: my: not found
email.pl: my: not found
email.pl: my: not found
email.pl: my: not found
email.pl: my: not found
email.pl: my: not found
email.pl: my: not found
email.pl: my: not found
email.pl: syntax error at line 19: `system' unexpected

Any suggestions?

My first guess is that it appears to not be finding perl, but is instead trying to run as a shell program... See if perl exists in the location that your script is checking:

ls -ail /usr/bin/perl

If it returns a message indicating perl: No such file or directory, you will need to find out where perl IS installed, and update your script with the proper path information:

which perl

or

find / -name perl -print

Seems your $cmd = ..... statement has wong double quote -
Try -
my $cmd = "uuencode $attachment |mailx -s $subj -c $cc $to -f $from";
Why are you making single quote around the mail options ?

I don't think it is require

You can check where perl is installed at the first place and then provide the path to perl interpreter
Check where perl installed and the version

perl -V

Perl is installed in the directory in which im running my script

can you just paste the out put of your perl path from which perl command

You can check if the path to the module are in @INC path ?
type in command promt :

perl -e 'use strict;'

if your path are ok this should work fine

What should happen when i execute the perl -e 'use strict;' on the command prompt. I didn't get anything on the prompt.

---------- Post updated at 11:24 AM ---------- Previous update was at 11:22 AM ----------

If i attempt to execute a different script it will work from the directory in which i'm running the current script that fails. This tells me that the path is correct.

identify a script that is working.

head -1 scriptname

Ensure that this line matches the line that starts your script.

The header of a working script matches my non functioning script.

Can you provide more information about your environment?
What OS are you using?
What version of perl are you using?
What shell are you running the script from?
What is your PATH?
What user are you running this script as? What user do you run the working script as?
Have you removed the second quotation mark identified by jambesh in an earlier response and tried the script again?

Provide as much detail as you can - it helps to eliminate the guesswork on our side.

---------------
It is syntactically correct in my system -Pls check the compilation out put

----
bash-3.2$ cat mail.pl
#!/usr/bin/perl -w
use strict;
use warnings;

my $baseDir = '/export/home/omcadmin/bin';
my $attachment = "$baseDir/message.txt";

my $from = 'xxx@xxx.com';
my $to = 'xxx@xxx.com';
my $cc = 'xxx@xxx.com';
my $subj = 'Testing';
my $body = 'TEST';

my $cmd = "uuencode $attachment |mailx -s $subj -c $cc $to -f $from";
system("$cmd");

---
bash-3.2$ perl -wc mail.pl
mail.pl syntax OK

I finally got the script to work after several modifications:

#!/usr/bin/perl -w

use strict;
use warnings;

my $attachment = 'something.jpg';

my $from = 'xxx@domain.com';
my $to = 'xxx@domain.com';
my $cc = 'xxx@domain.com';
my $subj = 'Testing';
my $body = 'TEST';

my $cmd = "uuencode $attachment $attachment | mailx -r $from -s $subj -c $cc $to";
system ("$cmd);

I finally got the code to send attachments. Now, i'm trying to figure out how to include the body into my statement.

Sorry bothering everyone regarding this problem.