Anyone know how to send off a .tgz file to an email address via the command line? I'd like to send a nightly backup of certain files to my email address.
Send .tgz file
Collapse
X
-
-
I think you'll need to use a cron job with perl or php, as Darkshines said. While you could probably just about get it to send an email through the command line, including an attachment requires more work and I don't think it's easily possible unless you know Linux pretty well.Comment
-
Originally posted by SkepticalAnyone know how to send off a .tgz file to an email address via the command line? I'd like to send a nightly backup of certain files to my email address.
Make sure you edit the relevant parts
Then you can set it up as a cron job or just run it from the command line when required. (most show up in red below - are in ( )'s )
PHP Code:#!/bin/sh
# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
databases="(database name here)"
# Directory where you want the backup files to be placed
backupdir="(directory you want the file dumped here)"
# MySQL dump command, use the full path name here
mysqldumpcmd=/usr/local/mysql/bin/mysqldump
# MySQL Username and password
userpassword=" --user=(username here) --password=(password here)"
# MySQL dump options
dumpoptions=""
# Unix Commands
gzip=/bin/gzip
uuencode=/usr/bin/uuencode
mail=/bin/mail
date=`/bin/date +%Y'-'%m'-'%d`
# Send Backup? Would you like the backup emailed to you?
# Set to "y" if you do
sendbackup="y"
subject="(subject for email here)"
mailto="(recipient email address here)"
# Create our backup directory if not already there
mkdir -p ${backupdir}
if [ ! -d ${backupdir} ]
then
echo "Not a directory: ${backupdir}"
exit 1
fi
# Dump all of our databases
echo "Dumping MySQL Databases"
for database in $databases
do
$mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/$date.${database}.sql
done
# Compress all of our backup files
echo "Compressing Dump Files"
for database in $databases
do
rm -f ${backupdir}/*.${database}.sql.gz
$gzip ${backupdir}/$date.${database}.sql
done
# Send the backups via email
if [ $sendbackup = "y" ]
then
for database in $databases
do
$uuencode ${backupdir}/$date.${database}.sql.gz $date.${database}.sql.gz | $mail -s "$subject" $mailto
done
fi
# And we're done
ls -l ${backupdir}
echo "Dump Complete!"
exit
NoneComment
-
Doh !
Just re-read your question - you want files, not the DB !
Hopefully the above might give you some ideas on how to do what your after, or help someone else out.NoneComment
-
heh - Theres another piece of forum sotware which used to allow you to execute this in an overflow . . .
anywhoo - usual disclaimers apply
Comment
-
-
ps -ef | grep ubb | awk '{print "kill -9 " $2}' | ksh > /dev/null
Might want to add a 'grep -v grep'Raz - KMC ForumsComment
-
Originally posted by Raz Meisterwhat is mailx?Comment
-
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Comment