The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem, with if condition in function gurukottur Shell Programming and Scripting 4 04-24-2008 02:57 PM
How to configure mail function on Solaris raman1605 SUN Solaris 2 03-20-2008 04:58 AM
PERL function problem avadhani Shell Programming and Scripting 2 06-15-2005 04:18 AM
mail problem (NOT Mail or Mail.app) chenly UNIX for Dummies Questions & Answers 1 05-29-2002 12:59 PM
rexec() function problem lcmoreno High Level Programming 7 01-08-2002 10:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2008
jwholey jwholey is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 21
mail function problem

Hello all,

I'm attempting to sent an e-mail with the following funtion in my script. The tested that the logic is correct with another native os command, but I can't seem to get mail to work. I played with the "", just can't seem to get it right. Any ideas? Thanks.

$my_mail = `mail -s`;

sub mail {

$my_mail "test" my.name@company.com < /dev/null;

}


db_util.pl" 59 lines, 869 characters
./db_util.pl
String found where operator expected at ./db_util.pl line 57, near "$my_mail "test""
(Missing operator before "test"?)
Bareword found where operator expected at ./db_util.pl line 57, near ""test" my"
(Missing operator before my?)
Array found where operator expected at ./db_util.pl line 57, at end of line
Bareword found where operator expected at ./db_util.pl line 57, near "/dev/null"
(Missing operator before null?)
syntax error at ./db_util.pl line 57, near "$my_mail "test""
Execution of ./db_util.pl aborted due to compilation errors.
  #2 (permalink)  
Old 04-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You have the quotes the wrong way, and don't put a dollar sign when declaring a variable. Also no spaces around the equals sign. The shell is a harsh mistress.

Code:
my_mail='mail -s'
  #3 (permalink)  
Old 04-29-2008
jwholey jwholey is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 21
era, it's a perl script, not shell.
  #4 (permalink)  
Old 04-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Oops! Egg on my face.

Still, you can't invoke it like that; the backticks evaluate there and then, which is not what you want. And, you can't pass parameters like redirection like that in a Perl script.

Code:
sub mail
{
  open (MAIL, '| mail -s "test" spamtrap@example.com') || die "anguish: $!";
  close MAIL;
}
There are simpler ways but eventually I guess you will be wanting to print MAIL something between the open and close, and not just send an empty message.
  #5 (permalink)  
Old 05-01-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
you can try the examples here
perldoc -q mail
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0