LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-19-2015, 02:38 AM   #16
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319

Quote:
Originally Posted by alaios View Post
Code:
if [[ $! -eq 0 ]]
This (in both places) should be
Code:
if [[ $? -ne 0 ]]
That is why you are getting the failure email when things are actually working.
 
Old 06-19-2015, 02:56 AM   #17
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by alaios View Post
I also still have commented the following

# 6. Remove the file that it was sent over email. Would not be dangerous to call rm and delete also other files?
#rm -f $COMPRESSEDFILENAME


I am scared that the $COMPRESSEDFILENAME might get some "funny" value and destroy my file system. I am running these scripts as root user and I still do not feel safe.
In order to gain confidence, you could add a line to report $COMPRESSEDFILENAME so you can see if it is correct:
Code:
echo $COMPRESSEDFILENAME
If you are running the script yourself at the command line, that will print $COMPRESSEDFILENAME. If you are running it by cron, I think it will email it to the cron user, which is root in your case.

By the way, why are you running it as root? If you own the files as a regular user, you should be able to run the script in that user's crontab. That would be safer. As a general security practice, I would only run a script as root if it really needed root privileges, and I would make sure no other user can modify or run the script.
 
Old 06-19-2015, 07:25 AM   #18
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
If it were me, I would cut-short this effort to "homebrew" yet-another backup tool, and grab one of the great-many fully featured tools that are already out there: open-source or commercial. A backup process, in order to be truly effective, must run constantly throughout the day ... must secure the backup files where only the backup daemons can get to them ... and must be truly bulletproof. I've seen a lot of cases where the client kit-bashed something together which utterly let them down when they actually tried to use it. (And another case where an intruder was tapping into the backup datasets as a way of completely circumventing the security of the stored data!)
 
Old 06-20-2015, 07:12 AM   #19
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Thanks for the last suggestion.
What is your loved featured tool out there?
Regards
Alex
 
Old 06-22-2015, 03:44 AM   #20
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Hi all,
I have decided over the weekend to finish the script and not allow my self to go for external programs for a simple task like that.
Currently the code runs but after finishing with the zipped file, the script stays "hanging" (no command prompt returnd back nor I receive any email). Any ideas what might be causing this?

Regards
Alex

Code:
#!/bin/bash

# Description. This script is for compressing my thesis folder and then sending it over email. Once the email is succesfully sent remove the compressed file. 



SCRIPTNAME=$(basename ${0})
MAILADDRESS="HideForNow"
THESISFOLDER="HideForNow"
TEMPSAVEFOLDER="HideForNow"
TIMESTAMP=$(date +%F)
COMPRESSEDFILENAME="$TEMPSAVEFOLDER"myname_thesis"$TIMESTAMP".tar.bz2


doEmail() { case "$1" in
        4)      REASON="Failed To compress File. $(echo $SCRIPTNAME)"
                SUBJECT="Thesis Backup Script failed"
                ;;
        5)      REASON="Failed to send email $(date). $(echo $SCRIPTNAME)"
                SUBJECT="Thesis Backup Script failed "
                ;;
        6)      REASON="Failed to remove file$(date). $(echo $SCRIPTNAME)"
                SUBJECT="Thesis Backup Script failed "
                ;;

        7)      REASON="Backup Script Finished. $(echo $SCRIPTNAME)"
                SUBJECT="Thesis Backup Completed"
                ;;

 *) echo "Please don't do that, Dave..." >/dev/stderr;;
esac; echo "${REASON}" | mail -r $MAILADDRESS -s "${SUBJECT}" $MAILADDRESS; }





# 4. Compress Email 
tar -jcvf "$COMPRESSEDFILENAME" "$THESISFOLDER"


if [[ $? -ne 0 ]]
then
    doEmail 4; exit 1; # Compressing the file failed
fi

#5. Send the File by email.
mail -r $MAILADDRESS -s "Thesis Backup $TIMESTAMP" -a $COMPRESSEDFILENAME $MAILADDRESS;


if [[ $? -ne 0 ]]
then
    doEmail 5; exit 1; # Sending email failed 
fi


# 6. Remove the file that it was sent over email. Would not be dangerous to call rm and delete also other files? 
#rm -f $COMPRESSEDFILENAME

# 7. Everything went as planned. Bye By 
doEmail 7; exit 0; # Exit 0 when normally returns
 
Old 06-23-2015, 02:29 AM   #21
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Thanks the problem seems to be this command

mail -r $MAILADDRESS -s "Thesis Backup $TIMESTAMP" -a $COMPRESSEDFILENAME $MAILADDRESS;


that expects me to press Control+D in console to send the email and the script then to terminate succesfully..

Any ideas on how to make send the mail as it is without waiting for user confirmation?

Regards
Alex
 
Old 06-23-2015, 06:54 AM   #22
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
echo "This is the message body" | mail -s "This is the subject" mail@example.com
http://www.binarytides.com/linux-mail-command-examples/
 
Old 06-23-2015, 08:02 AM   #23
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
but where is your attachment?
 
Old 06-23-2015, 10:14 AM   #24
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by schneidz View Post
Quote:
Originally Posted by alaios View Post
but where is your attachment?
For sending attachments, the above-linked article recommends a mail utility called mutt.

Last edited by Beryllos; 06-23-2015 at 12:02 PM.
 
Old 06-23-2015, 10:32 AM   #25
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Is there a specific reason to be using email to transfer the backup?
I can think of two specific reasons:
  • Method of getting file from Computer A to Computer B
  • Method of storing file on mail server (like on gmail account)

#1 would be a lot more efficient and easier with rsync or scp and #2 would be a lot more practical with a online cloud backup.
I know a few people who email files to themselves to back it up and it's generally because they don't know any better way.
 
1 members found this post helpful.
Old 06-25-2015, 05:46 AM   #26
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
mailx with attachment (RHEL6 or similar) https://access.redhat.com/solutions/104833
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tar fails on system backup - need to backup remote web server cilbuper Linux - General 2 08-26-2014 12:28 AM
Today is World Backup Day – a friendly reminder to backup and check restores jeremy Linux - News 0 03-31-2014 11:42 AM
[SOLVED] Backup, shrink backup and modify MBR of backup jps1x2 Linux - General 1 12-17-2013 05:03 AM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
LXer: GPLv3 adoption is up 14% week over week LXer Syndicated Linux News 0 08-23-2007 01:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:01 AM.

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