Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

mailx

by karu1975 (Initiate)
on Jun 18, 2003 at 23:03 UTC ( [id://267022]=perlquestion: print w/replies, xml ) Need Help??

karu1975 has asked for the wisdom of the Perl Monks concerning the following question:

hi all i am having problem executing the command system("mailx -s 'title' emailaddr < $file"); it gives me the error with the permissions of that file i:e sh: -rw-r--r--: cannot open . Kindly help is nedded

Replies are listed 'Best First'.
Re: mailx
by sauoq (Abbot) on Jun 19, 2003 at 00:02 UTC

    Sounds like you tried to get the filename into the $file variable by parsing it out of a directory listing. For example, you might have done something like

    for my $file (`ls -l /some/dir`) { ... }
    If you are going to do that, you'll need to improve your parsing. ;-)

    If you show us the code next time, you'll probably get a more thorough response.

    -sauoq
    "My two cents aren't worth a dime.";
    
      Further, if this is the case

      for my $file (`ls -l /some/dir`) { ... }

      then you may be interested in  ls -1, or better still, for a pure Perl method the  readdir function. From perlfunc:

      opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @files= grep { -f "$some_dir/$_" } readdir(DIR); closedir DIR;

      I use the following subroutine to wrap around mailx, which you may find to be a useful starting point

      # # mailit - send an email using mailx. Accepts either a $body or a path + # to a file # # Args: # $subject - email subject # either: # $body - body of email in scalar var, or # $fname - path to file to send. # @emails - list of email addresses to send email to # sub mailit { my ( $subj, $body, $fname, @email ) = @_; my($mailcmd) = "mailx -s\"$subj\""; die "Invalid mailit args\n" unless ($subj and ($body or $fname +)); if ($body) { foreach ( @email ) { open( PI, "|$mailcmd $_" ) or warn "Pipe to ma +ilx failed: $mailcmd\n"; print PI $body; print PI "\n.\n"; close PI; } } elsif ($fname) { die "Bad mailit path $fname\n " unless -e $fname; foreach ( @email ) { `$mailcmd $_ < $fname` or warn "bad mailx resp +onse: $?, $!"; } } }
      Disclaimer: modified for posting, so untested.

      mailit(), in conjunction with readdir, should do what you want.

      Hope this helps, bm.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://267022]
Approved by sauoq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2026-04-21 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.