View Full Version : Howto send an email via the command line?
Amygdala
01-23-2003, 07:53 PM
I have a script that first backups a db and then ftps it to a remote server.
How can I do a test that says if all that worked email me to tell me everything is OK, else tell me something is wrong?
It's a cron job btw.
Thanks
Amy
PS just the commands to email me would be fine, but the conditional stuff is a mystery to me too!
Spookster
01-23-2003, 08:24 PM
Can't really answer your questions when you don't tell us what language or shell you are using for your scripting. Perl? sh (Bourne Shell)? bash (Bourne Again Shell)? csh (C-Shell)? ksh (Korn Shell)?
Amygdala
01-23-2003, 08:36 PM
bash on redhat 7.2 sorry :o
Spookster
01-23-2003, 10:00 PM
Hmmm conditional statements in bash are fairly straight forward
http://steve-parker.org/sh/test.shtml
As for sending mail you can use the linux mail command. Of course I seem to recall that when you run a cron job a mail gets sent to root regardless unless it was disabled in your scripting. Has anyone checked root's email lately?
Amygdala
01-23-2003, 11:22 PM
Thanks, that test page looks good and should help me with the scripting side of it.
However, I was wondering if you could give me a hand with 'mail'.
for e.g. I want to do a test to see if something's worked and if it has then something like this to happen.
mail ( amygdala@home.com, subject="HEY IT WORKED", body="at so and so time etc." );
Now I know that isn't the syntax, but from the small mail --help it didn't help me work it out how to do that :(
Also, I was wondering how i might do the following (pushing luck here with you guys but I a newbie). Currently I run a backup:-
tar -czf sitebackup23-01-03.tar.gz /home/virtual/site/
I was wondering is there anyway of automatically getting the shell to put in the current date, so I can constantly automatically add to backups without overwriting previous ones?
I promise I'll stop asking newb questions in a bit!!! :)
Amy
Spookster
01-24-2003, 01:22 AM
if[expression]
then
mail username -s "Subject of Email"
Content of Email
Ctrl-d
fi
Amygdala
01-24-2003, 01:29 AM
Thank you thank you thank you thank you.
Did I thank you? :)
Amy
Spookster
01-24-2003, 01:40 AM
Well i'd make sure everything works first. lol :)
As far as the backups do you mean put the current date as part of the file name?
Amygdala
01-24-2003, 09:47 AM
Originally posted by Spookster As far as the backups do you mean put the current date as part of the file name? [/B]
Yep. Exactly that.... it would be better than using a static filename which would then get overwritten every time a backup was made.
Know a way?
Spookster
01-24-2003, 10:51 AM
Shouldn't be too hard. Just grab a timestamp from the system and use that as the filename.
Post the portion of your script where you have set the filename for the backup.
Amygdala
01-24-2003, 11:05 AM
$mysqldump -uusername -ppword dbname > /home/amygdala/backups/dbname-DATE.sql
Amygdala
01-26-2003, 10:58 AM
Anyone know how to add the date in dynamically using the command line in bash?
Spookster
01-26-2003, 05:52 PM
Ok try this:
$mysqldump -uusername -ppword dbname > /home/amygdala/backups/dbname-`date +%d_%m_%y`.sql
Amygdala
01-26-2003, 05:59 PM
Just the job. Thanks :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.