Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 21st, 2003, 12:05 PM
nindoja nindoja is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 147 nindoja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 21 m 53 sec
Reputation Power: 6
Question E-mailing a file via a cron job

Hello. I am trying to backup my mysql database, and have it e-mailed to me. I have the cron job set up to make the backup of the mysql database, and it works. The only thing that I need is a cron job that will automatically, at 12:30 A.M., e-mail me the backup file. How would I do this??? Thanks.

Reply With Quote
  #2  
Old June 21st, 2003, 02:33 PM
ralphch ralphch is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Buenos Aires, Argentina
Posts: 154 ralphch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 47 m 49 sec
Reputation Power: 8
Send a message via MSN to ralphch
Code a perl script that will pipe out the file through sendmail to your email address. And just set up this script on cron to run at 12:30AM every day.

Hope this helps.

Ralph.

Reply With Quote
  #3  
Old June 21st, 2003, 03:28 PM
nindoja nindoja is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 147 nindoja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 21 m 53 sec
Reputation Power: 6
Well, I don't exactly know how to code in Perl. The only information that I need in the e-mail is the attached file, no message or anything. Can someone make this script for me???

Reply With Quote
  #4  
Old June 21st, 2003, 07:07 PM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 20
Something like
mail -s "Database backup" you@somedomain.com < database.dmp
should work. Not the most reliable way though...

More info -> http://www.unix.com/showthread.php?threadid=568
http://www.unix.com/showthread.php?threadid=25

//NoXcuz
__________________
UN*X is sexy!
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep

Reply With Quote
  #5  
Old June 21st, 2003, 10:07 PM
nindoja nindoja is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 147 nindoja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 21 m 53 sec
Reputation Power: 6
That didn't work

Thanks, but doing "mail -s "Database backup" you@somedomain.com < database.dmp" doesn't stay in my crontab thing (it is cut down to mail -s). I don't know why. I also tried "metasend -b -t someone@somewhere.com -s "My webpage!" -m text/html -f mypage.html," but that also dissapeared from the crontab thing (it is cut down to metasend -b).
What else can I do???

Reply With Quote
  #6  
Old June 22nd, 2003, 12:54 PM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level)NoXcuz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 20
Use backticks, like
`mail -s "Database backup" you@somedomain.com < dumpfile.dmp`

The same should work for metasend (with backticks).

//NoXcuz

Reply With Quote
  #7  
Old June 23rd, 2003, 03:10 AM
swbush swbush is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 swbush User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Have a look at this:

http://www.cgi-interactive.co.uk/mysql_dump.html

It is a simple bash script, that extracts the db schema, compresses the data and emails you the backup.

Bash Shell Script (mysqlbackup)
======================
#!/bin/sh
mysqldump -uroot -ppwd --opt db1 > /sqldata/db1.sql

cd /sqldata/
tar -zcvf sqldata.tgz *.sql
cd /scripts/
perl emailsql.cgi

line #2 - change -u to be your db username
line #2 - change -p to be your db password

emailsql.cgi Script
=============
#!/usr/bin/perl -w

use MIME::Lite;

$msg = MIME::Lite->new(

From => 'mysqlbackup@yourdomain.com',
To => 'who.ever@yourdomain.com',
Subject => 'sqldata.tgz MySQL backup!',
Type => 'text/plain',
Data => "Hi WhoEverl,\n MySQL database backups.");

$msg->attach(Type=>'application/x-tar',
Path =>"/sqldata/sqldata.tgz",
Filename =>"sqldata.tgz");

$msg->send;

Next, edit your cron table, by running "crontab -e". This will open the cron table in your default text editor, when you save it the file will be reloaded and ready for use.

30 0 * * * * /path/to/mysqlbackup

This cron entry will run at 00:30 hours every morning.

Reply With Quote
  #8  
Old June 23rd, 2003, 10:35 AM
nindoja nindoja is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 147 nindoja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 21 m 53 sec
Reputation Power: 6
I figured it out

@NoXcuz: The reason that your command was getting cut off was because of the quotation marks... I removed them, and made the subject one word, and now it works.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > E-mailing a file via a cron job


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway