1834480 Members
3905 Online
110067 Solutions
New Discussion

Re: redirect tar?

 
SOLVED
Go to solution
Ian_79
New Member

redirect tar?

What am I doing wrong?
When I try something like
tar cvf /tmp/mytar.tar /tmp/error >/tmp/mytar.log
I do not get the expected .log file. While /tmp/mytar.log is created it is empty and tar -v still writes to the screen?

There is a tar command running from cron that backs up files. All I want to do is redirect the output of this command so that I can check the log file in the morning.

Ian
7 REPLIES 7
Indira Aramandla
Honored Contributor

Re: redirect tar?

Hi Ian,

You have a script to backup the files. And this script is scheduled using cron. If you want the output of the scheduled job, then you can specify the log in the cron schedule itself.

For example you have scheduled the script called "backup_tar.sh" which has the commands to backup the files using tar, and you schedule this script to run every day at 16:00 hours then do this.

00 16 * * * /path/backup_tar.sh > /path/logs/backup_tar_output.log

This backup_tar_output.log will have the output of the backup script execution.


Indira A
Never give up, Keep Trying
Muthukumar_5
Honored Contributor

Re: redirect tar?

Try as,

nohup tar cvf /tmp/mytar.tar /tmp/error so that it will log all details into nohup.log file.

If you get messages on screen then it may be ERROR messages. Try as,

tar cvf /tmp/mytar.tar /tmp/error 1>/tmp/mytar.log 2>&1

HTH.
Easy to suggest when don't know about the problem!
Ian_79
New Member

Re: redirect tar?

Thank-you both for your responses.

I have tried using nohup as suggested
nohup tar cvf /tmp/mytar.tar /tmp/error.
I still got the tar listing on the screen and couldn't find the nohup log in either the current directory or the $HOME directory?

When I try
tar cvf /tmp/mytar.tar /tmp/error 1>/tmp/mytar.log

I get an error message saying
tar : cannot stat 1. not dumped
Can I tell tar that 1 is not a file to be added to the archive?

This is not a major problem for me as I can write a script for the cron job as suggested by Indira.
I am still curious and frustrated as to why I can't achieve this seemly simple redirection. I have no problems achieving this in Linux but fails with HPUX.

Ian.
Ermin Borovac
Honored Contributor
Solution

Re: redirect tar?

tar is sending verbose messasages to standard error, so you'll need to redirect both standard output and standard error to your file.

It looks like you are using csh, therefore use

$ tar cvf test.tar >& tar.log
Robert Salter
Respected Contributor

Re: redirect tar?

Ian,

tar cvf /tmp/mytar.tar /tmp/error > /tmp/mytar.log 2>&1

will do it for you.

bueno bye
Time to smoke and joke
Rick Garland
Honored Contributor

Re: redirect tar?

Have you tried the "tee -a" option?

LOGFILE=/tmp/mytar.log
tar cvf /tmp/mytar.tar /tmp/error | tee -a $LOGFILE


Ian_79
New Member

Re: redirect tar?

Thanks to all of you who took the time to answer my problem. Ermin is exactly right I didn't realise that verbose was using stderr. I also didn't pick up that the account I was using was using the c shell and not posix - ooops.