LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-05-2011, 04:45 AM   #1
amario26
LQ Newbie
 
Registered: Apr 2011
Posts: 11

Rep: Reputation: 0
output of a tar command not sending to my E-Mail


Hi,

Basically I have a script that runs every day (via crontab) and it works perfectly! Only problem is that the job will only send the output of most of the stuff and not the tar bit..

This is the main part of my script:

Code:
if (( $days1 <= 5 ))
           then
                echo
		echo "*******" "Begin Removing All Previous Log Files" "*******"
			rm ./*cron.log
		echo
		echo "*******" "Begin Removing Files" "*******" 
			ssh username@servername rm ./../test/$TODAY/*.gz
		echo
		echo "*******" "Checking the following directories: $BACKUP" "*******"
		echo
		set -- $BACKUP
			DIRS=$@
			for i in "$@"
				do
				if [ -d $i ]; then
				echo "Directory $i exists"
				else
				echo "!!!!!!! Directory $i doesnt exist - This directory will not be backed up. Your backup will continue as normal, skipping this directory. !!!!!!!"
			fi
		done
		echo
		echo "*******" "Begin compressing and transferring files" "*******"
		echo
			tar -czp $BACKUP | ssh -c blowfish username@servername "dd of=/home/test/$TODAY/"$DATETIME"__TestBackup.tar.gz"
		echo
           else
                echo "Your backup has failed"
     fi
done
It will only email me up to the bit where it says echo "*******" "Begin compressing and transferring files" "*******" after that it wont email me the output of the tar command just below it...

Here is my crontab line that does the mailing:

Code:
00 22 * * 1-5 bash /home/user/RoutineBackupTest.sh | mail -s "Backup Log" firstname.surname@company.com
Do any of you experts know why that is? I've been trying for ages to figure it out! I cant even get mutt -a to work.. nor tee..

Many thanks for your help in advance, its appreciated.
 
Old 05-05-2011, 05:20 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
The standard output stream of tar is the tarfile itself (which is put by the script into the backup file). I'm guessing that what you want to see is the standard error stream, where diagnostics are more often sent.

Since your crontab script only pipes the stdout to the email, you are losing the stderr output. In bash you can use something like this to pass both stderr and stdout through the pipe to the email:

Code:
00 22 * * 1-5 bash /home/user/RoutineBackupTest.sh 2>&1 | mail -s "Backup Log" firstname.surname@company.com
(where the '2>&1' says to redirect stderr output to stdout)

Alternatively you can just use:

Code:
00 22 * * 1-5 bash /home/user/RoutineBackupTest.sh |& mail -s "Backup Log" firstname.surname@company.com
(which might be more portable, in cases where you aren't using bash)

Last edited by neonsignal; 05-05-2011 at 05:28 AM.
 
1 members found this post helpful.
Old 05-05-2011, 06:03 AM   #3
amario26
LQ Newbie
 
Registered: Apr 2011
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks neonsignal!

That was pretty much what I wanted but the only thing is now that when the E-Mail arrives it tells me its failed.. It was working before I added '2>&1' to the crontab as you suggested.. any ideas?

Many thanks
 
Old 05-05-2011, 06:09 AM   #4
amario26
LQ Newbie
 
Registered: Apr 2011
Posts: 11

Original Poster
Rep: Reputation: 0
Actually.. ignore me.. I was typing some stuff and my fat fingers made a typo!

Thanks dude!
 
  


Reply

Tags
crontab, mail, tar, tar gzip backup


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Sending mail from command line Geert86 Linux - Server 10 11-30-2009 12:04 PM
Sendmail (mailserver) -- sending mail with the mail command -- doesn't work :-( carolinevdh Linux - Server 1 08-13-2009 09:43 PM
tar command output redirection ah_kayyali Linux - Newbie 4 03-19-2006 06:30 AM
Sending output to mail account through cron. gian2oo1 Slackware 2 01-18-2005 12:54 PM
Sending mail through command prompt moger Linux - General 1 02-18-2003 02:27 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration