LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-22-2005, 06:03 AM   #1
Athas
LQ Newbie
 
Registered: Jan 2005
Distribution: fedora
Posts: 10

Rep: Reputation: 0
Filename zip stdin


I've been trying to get a shell script working that would mail me a database backup but I can't seem to get it working correctly the problem is that the filename for the sql file is - which I cant use through the cli as it thinks that I'm trying to use stdin instead of a filename

Code:
#!
mysqldump -u root -ppassword databasename  |zip backup.zip -
uuencode backup.zip backupzip.zip | mail fake@example.com -s"Database backup"
I'd like the filename within the zip to be something like backup-22-09-05.sql Is this possible?
I'd also like to insert the date in the email subject if possible.

Thanks,
Wesley
 
Old 10-22-2005, 06:22 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
This seems a little confused.

I'll ignore your code which makes it appear you ARE using "-" for stdin and just answer what you wrote about the file name being "-".

If you really need to name it "-" then you can escape the special meaning of "-" by typing "\-" instead of just "-".
 
Old 10-23-2005, 09:56 AM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Here's a snippet from mine, which does what yours is trying to do, in a slightly different way:
Code:
EMAILTO="me@mydomain.com"
MYSQL=$(/usr/bin/which mysqldump 2>/dev/null)
dumpdate=$(date "+%Y%m%d%H%M")
if $MYSQL -u username -ppassword databasename > $HOME/backups/$dumpdate.backup
then
    echo "Database backed up to $dumpdate.backup"
    # cpio the archive and email it to the recipient list
    cd $HOME/backups
    echo $dumpdate.backup | /bin/cpio -o | uuencode $dumpdate.backup |
                                /bin/mail -n -s "$dumpdate Archive" $EMAILTO
else
    echo "Database not backed up"
    [ -f $HOME/backups/$dumpdate.backup ] && rm $HOME/backups/$dumpdate.backup
    exit 1
fi
 
Old 10-23-2005, 01:30 PM   #4
Athas
LQ Newbie
 
Registered: Jan 2005
Distribution: fedora
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks very much this looks useful,
since my original post I tried to do this a different way. However much to my disgust I've realised that uuencode isn't on my web-server. Is there any other way to send an attachment through the CLI?

For reference here is the code that I'm currently using, in case anyone else finds it useful

Code:
#!/bin/csh
set todaysDate=`date +%a_%d_%b_%y`
mysqldump -u username -ppassword dbName > dbName_${todaysDate}.sql
zip backup backupname${todaysDate}.sql
uuencode backup.zip backupname${todaysDate}.zip | mail test@example.com -s"Database backup ${todaysDate}"
rm backupname${todaysDate}.sql
rm backup.zip
Thanks,
Regards,
Wesley

Last edited by Athas; 10-23-2005 at 01:32 PM.
 
Old 10-29-2005, 04:56 AM   #5
Athas
LQ Newbie
 
Registered: Jan 2005
Distribution: fedora
Posts: 10

Original Poster
Rep: Reputation: 0
Solution

The webserver didn't have uuencode installed but they did have mutt installed.

Theres a good article on sending email attachments
http://www.shelldorado.com/articles/...tachments.html
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
change uploaded files from filename.avi to filename.avi.html like www.rapidshare.de latheesan Linux - Newbie 3 06-16-2005 04:33 AM
Statistics from stdin? edeca Linux - Software 0 05-23-2005 10:03 AM
filename- and filename~ files? slinky2004 Linux - Newbie 5 10-17-2004 10:32 PM
create a self-extracting zip file with zip on solaris? samsolaris Solaris / OpenSolaris 3 10-15-2004 01:50 AM
unbuffered stdin mvt Programming 7 05-17-2004 09:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:45 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
Open Source Consulting | Domain Registration