perl script to send an email executing with errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script to send an email executing with errors
# 1  
Old 04-20-2010
perl script to send an email executing with errors

Hello , i am using RHEL5 , i have got a perl script that executes and sends an email correctly if i run it with ./sendemail.sh command. This is the script below

Code:
#! /usr/bin/perl
use Net::SMTP;
print "starting email send .";
$smtp = Net::SMTP->new("192.168.0.1");
$smtp->mail("c.baranga\@cit.mak.ac.ug");
$smtp->to("a.agaba\@cit.mak.ac.ug");
$smtp->data;
$smtp->datasend("Subject: Remote Server Login Attempt");
$smtp->datasend("\n");
$smtp->datasend("Check your secure.Log now ..");
$smtp->dataend;
$mssg = $smtp->quit;
print "$mssg";
print "finished, email sent ";



what i want it to achive is , for every remote login attempt on the server, it should be triggered .. so i put it in /etc/profile.d/ and , it is being triggered , but with errors , below is the error it shows

Code:
-bash: use: command not found
-bash: print: command not found
-bash: /etc/profile.d/sendemail.sh: line 4: syntax error near unexpected token `('
-bash: /etc/profile.d/sendemail.sh: line 4: `$smtp = Net::SMTP->new("192.168.0.1");'

when i execute it directly alone it works with no errors, but when i try to login remotely, it is successfully triggered but shows errors so it doesnt send the mail eventually.. is there something am doing wrongly ? ...

Last edited by pludi; 04-20-2010 at 05:22 AM.. Reason: code tags, please...
# 2  
Old 04-20-2010
How do you run the script from command prompt ?

Why is the script extension .sh ? when its a perl script ?
# 3  
Old 04-20-2010
dinjo_jo .
i first make it executable and then in the same folder it is i type ./sendemail.sh , and it runs as expected.
the reason as to why its .sh , is to make it a bash script such that it can be triggered by the system easily ..... what do you think
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Executing of UNIX script using email

Dear Unix Leads, can you please let me know is it possible to execute a shell script in UNIX machine sending an email from outlook or gmail ? or is it possible to generate a token file in UNIX by sending email which we can indirectly use to trigger script your response on this is highly... (5 Replies)
Discussion started by: mirwasim
5 Replies

2. Shell Programming and Scripting

Need little script to send out email

Hi Scripters, good day. bash-4.2# df -g /apps/prd Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/xxx 64.00 4.35 94% 1269284 8% /xxx bash-4.2# I was wondering if there is a script when the usage of the mountpoint above hit 98%, email would be... (3 Replies)
Discussion started by: jaapar
3 Replies

3. Shell Programming and Scripting

shell_script showing errors in the below mentioned script while executing in linux

code: IMAGE=$imgvalue; if then echo DO=ABC; elif then echo DO=ETC; elif then echo DO=XYZ; else echo "$imgvalue is unsupported"; exit 1; fi in above script IMAGE=1 , IMAGE=2, IMAGE=3 whatever may be the value i have assigned it's showing only DO=ABC other conditions... (7 Replies)
Discussion started by: saku
7 Replies

4. Shell Programming and Scripting

Bash script errors when executing

I'm working on a script that will search through a directory for MKV files and remux them to MP4. I found a few other scripts around the net that do this, but they all have limitations that don't always get the job done. The main limitation I've found is that most scripts look for the video track... (2 Replies)
Discussion started by: rayne127
2 Replies

5. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

6. Shell Programming and Scripting

How to automatically send a mail alert if the script errors out

I have a script like this, which calls other scripts from that script: #!/usr/ksh moveFiles.sh extract.sh readfile=/home/sample.txt cat $readfile | while read line do file= `echo $line|awk '{print $4}'` if ; then mv $file /home/temp_stage fi (4 Replies)
Discussion started by: ss3944
4 Replies

7. Shell Programming and Scripting

send an email of script output

Hi All, I'm trying to send some file which generated by script to my email. when I run the script I'm getting an email. Thats fine. But it seems to be all messed up like below Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA:... (4 Replies)
Discussion started by: s_linux
4 Replies

8. Shell Programming and Scripting

Send email on script error

I need to start off by saying that I am not much of a programmer and know enough to cause lots of trouble. I've been writing this script to decrypt an XML feed, then parse the feed into a database. The script is executed from cron. #!/bin/sh PGPPATH=/path/to/directory echo "pgp... (6 Replies)
Discussion started by: Aslan_Eident
6 Replies

9. Shell Programming and Scripting

avoid displaying errors while executing a script

Hi all, I am running a script on bash shell, although it gives me the desired output, it displays some errors at the prompt like this directory doesnt exists unary operator etc etc Is there someway to avoid these errors ?? Its very annoying to have these errors while the script is... (4 Replies)
Discussion started by: vikas027
4 Replies

10. Shell Programming and Scripting

script that will send and email attachment

I'm looking for a sample of some code that will take the output from a file and generate an email that will include that text as an attachment. the script is in the borne shell. any help? (2 Replies)
Discussion started by: davels
2 Replies
Login or Register to Ask a Question