Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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


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:

if (( $days1 <= 5 ))
		echo "*******" "Begin Removing All Previous Log Files" "*******"
			rm ./*cron.log
		echo "*******" "Begin Removing Files" "*******" 
			ssh username@servername rm ./../test/$TODAY/*.gz
		echo "*******" "Checking the following directories: $BACKUP" "*******"
		set -- $BACKUP
			for i in "$@"
				if [ -d $i ]; then
				echo "Directory $i exists"
				echo "!!!!!!! Directory $i doesnt exist - This directory will not be backed up. Your backup will continue as normal, skipping this directory. !!!!!!!"
		echo "*******" "Begin compressing and transferring files" "*******"
			tar -czp $BACKUP | ssh -c blowfish username@servername "dd of=/home/test/$TODAY/"$DATETIME"__TestBackup.tar.gz"
                echo "Your backup has failed"
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:

00 22 * * 1-5 bash /home/user/ | mail -s "Backup Log"
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
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
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:

00 22 * * 1-5 bash /home/user/ 2>&1 | mail -s "Backup Log"
(where the '2>&1' says to redirect stderr output to stdout)

Alternatively you can just use:

00 22 * * 1-5 bash /home/user/ |& mail -s "Backup Log"
(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
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
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!


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration