LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2005, 07:22 PM   #1
stefaandk
Member
 
Registered: Jun 2005
Distribution: Centos
Posts: 215

Rep: Reputation: 30
Send mail from prompt


Hi,

Could anyone help me with the following:

I want a script that I would put in a cronjob doing the following:

Print the contents of a directory to a file and then email that file to me on a daily basis.

Thanks,

Stefaan
 
Old 06-07-2005, 07:47 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 376Reputation: 376Reputation: 376Reputation: 376
this would mail you the contents directly:
Code:
ls /example | mail -s "Contents of /example" your@email.com
this would put the contents in a text file and send the file as an attachment:
Code:
ls /example > /tmp/example.txt
echo "Here's your daily file..." | mail -s "Contents of /example" \
-a /tmp/example.txt your@email.com
just my ...


Last edited by win32sux; 06-07-2005 at 07:49 PM.
 
Old 06-07-2005, 08:05 PM   #3
stefaandk
Member
 
Registered: Jun 2005
Distribution: Centos
Posts: 215

Original Poster
Rep: Reputation: 30
Ripper, that seems to work fine, the attachment one however stumbles over the -a option, doesn't seem to exist, running FC2.

But I'm not that fuzzed in having it as an attachment.

Cheers mate.
 
Old 06-07-2005, 08:11 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 376Reputation: 376Reputation: 376Reputation: 376
hmmm, that's weird... do a "man mail" and confirm your mail command supports the "-a" option...

EDIT: wait, do you mean the "-a" option doesn't exist or do you mean the file you want to attach doesn't exist??

 
Old 06-07-2005, 08:19 PM   #5
stefaandk
Member
 
Registered: Jun 2005
Distribution: Centos
Posts: 215

Original Poster
Rep: Reputation: 30
man mail doesn't list -a as an option nor do I see any references to attachments.
 
Old 06-07-2005, 08:28 PM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 376Reputation: 376Reputation: 376Reputation: 376
well, i'm on slackware, so "mail" is a link to "nail", as you can see here:
Code:
win32sux@darkstar:~$ ls -l /usr/bin/mail
lrwxrwxrwx  1 root root 4 2005-04-04 14:29 /usr/bin/mail -> nail*
and this is nail: http://nail.sourceforge.net/

so when i do a "man mail" i can see the "-a" option in there:
Quote:
-a file
Attach the given file to the message.
plus i know it works cuz i use it... so yeah, looks like the mail tool included in FC2 doesn't support attachments... but still, that's kinda weird...
 
Old 06-07-2005, 08:31 PM   #7
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
I don't think "mail" handles mime type attatchments. I would do it like this:

10 17 * * Mon-Fri ls -l ~/tmp > ~/tmp_dir.txt | cat ~/tmp_dir.txt | mail -s "tmp_dir"
kencaz@linuxmail.org

This would create a file tmp_dir.txt in my home folder and mail me the contents but not as an attatchment everyday at 5:10pm

KC
 
Old 06-07-2005, 08:32 PM   #8
stefaandk
Member
 
Registered: Jun 2005
Distribution: Centos
Posts: 215

Original Poster
Rep: Reputation: 30
Right, I'll have to install nail then coz I do see a need for attachments sent from the prompt coz I want to mail things like the history file etc.

You've been most helpfull!
 
Old 06-07-2005, 08:45 PM   #9
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 376Reputation: 376Reputation: 376Reputation: 376
Quote:
Originally posted by kencaz
ls -l ~/tmp > ~/tmp_dir.txt | cat ~/tmp_dir.txt | mail -s "tmp_dir"
kencaz@linuxmail.org
or you can eliminate that file and the cat command and get the same effect (like in my first example):
Code:
ls -l ~/tmp | mail -s "tmp_dir" kencaz@linuxmail.org
PS: why are you using a pipe before the cat after you've redirected the ls output to the .txt file??


Last edited by win32sux; 06-07-2005 at 08:49 PM.
 
Old 06-07-2005, 08:49 PM   #10
chaibloom
LQ Newbie
 
Registered: Jun 2005
Posts: 1

Rep: Reputation: 0
Mail with a different "from" address

I'm looking for something similar. I can use "mail" to send mail from a command line, but there seems to be no way to specify an a different return address. Does anyone know of a utility other than "mail" that will let you change the reply-to address?

Thanks!

Cory
 
Old 06-07-2005, 08:59 PM   #11
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
Quote:
Originally posted by win32sux
or you can eliminate that file and the cat command and get the same effect (like in my first example):
Code:
ls -l ~/tmp | mail -s "tmp_dir" kencaz@linuxmail.org
PS: why are you using a pipe before the cat after you've redirected the ls output to the .txt file??
True, you could do it that way, however, ls -l ~/tmp | mail -s "tmp_dir" kencaz@linuxmail.org would not create the file "tmp_dir.txt" in my $HOME folder. It would just send me the contents of ls...

I'm sure there are probably 5 other ways to do it, but that's what just came to mind at the time.

KC
 
Old 06-07-2005, 09:37 PM   #12
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 376Reputation: 376Reputation: 376Reputation: 376
okay, but i'm still not sure what the pipe in red in your commands is doing:
Code:
ls -l ~/tmp > ~/tmp_dir.txt | cat ~/tmp_dir.txt | mail -s "tmp_dir" kencaz@linuxmail.org
i assume you meant for it to be a semicolon instead... like:
Code:
ls -l ~/tmp > ~/tmp_dir.txt ; cat ~/tmp_dir.txt | mail -s "tmp_dir" kencaz@linuxmail.org
 
Old 06-07-2005, 09:37 PM   #13
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 376Reputation: 376Reputation: 376Reputation: 376
Re: Mail with a different "from" address

Quote:
Originally posted by chaibloom
I'm looking for something similar. I can use "mail" to send mail from a command line, but there seems to be no way to specify an a different return address. Does anyone know of a utility other than "mail" that will let you change the reply-to address?
you can do this with the "-r" option, at least if you are using nail...
Quote:
-r address
Sets the From address. Overrides any from variable
specified in environment or startup files. Tilde
escapes are disabled. The -r address options are
passed to the mail transfer agent unless SMTP is
used.
 
Old 06-07-2005, 09:58 PM   #14
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
Quote:
Originally posted by win32sux
okay, but i'm still not sure what the pipe in red in your commands is doing:
Code:
ls -l ~/tmp > ~/tmp_dir.txt | cat ~/tmp_dir.txt | mail -s "tmp_dir" kencaz@linuxmail.org
i assume you meant for it to be a semicolon instead... like:
Code:
ls -l ~/tmp > ~/tmp_dir.txt ; cat ~/tmp_dir.txt | mail -s "tmp_dir" kencaz@linuxmail.org
You are very correct win32sux. A separator will do the same thing and is the proper way...

KC
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can send and recieve local mail, but not mail from internet Caine101022 Linux - Software 2 09-09-2005 02:35 PM
how to configure mail client to send mail out on different pppd threads vkrishn1 Linux - Newbie 0 12-29-2004 11:54 AM
Server does'nt send mail until shutdown and LAN can't send or receive. Wolfy Linux - Networking 0 08-02-2004 08:31 PM
Cannot send mail with mail() command in PHP 4.3.4, Apache 2.0.48, Mandrake Linux 10 arcanum Linux - General 3 06-27-2004 07:06 PM
Open web mail OR Send mail groups linuxeagle Linux - Networking 0 05-12-2004 02:54 PM


All times are GMT -5. The time now is 12:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration