LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 05-12-2005, 04:40 PM   #1
buster_balz
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Rep: Reputation: 0
Scripting question


This is probably something easy that I just missed, but here goes.
I am writing a backup script that uses dump. Standard output from the command are being written to a logfile but But I can't get dump to write it's output to the log file. an example of what I'm trying to do is below

export LOGFILE=/root/logs/backup.log
echo "Beginning backup" >$LOGFILE
dump -u -f /dev/st1 /root >>$LOGFILE

the output is still being sent to the screen. What am I missing?
 
Old 05-12-2005, 04:54 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
dump's output is probably being printed on stdout. Add '2>&1' after the redirection to the logfile.
 
Old 05-12-2005, 08:09 PM   #3
buster_balz
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Like this?

dump -u -f /dev/st1 /root >>$LOGFILE 2>&1
 
Old 05-12-2005, 08:51 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
exactly. This redirects IO stream '2' (standard error) to the same place as stream '1' (standard output), where you have already set it to append to the logfile.
 
Old 05-13-2005, 09:51 AM   #5
buster_balz
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Any other suggestions?

I tried the redirection of STDOUT and STDERR,

dump -u -f /dev/st1 /root >>$LOGFILE 2>&1

but it does not work. Maybe I have the syntax wrong here?
 
Old 05-13-2005, 10:57 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
That's very odd. You're getting output from dump?
 
Old 05-16-2005, 12:59 PM   #7
buster_balz
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Yes, the output is

from dump. It lists the progress, and that sort of thing. I would prefer to have it redirected to my log file, but it doesn't seem to want to cooperate.
 
Old 05-18-2005, 04:03 PM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,192

Rep: Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538
I had a similar problem when writing my back-up script. I too did the 2>&1, but it did not the effect that both stdout and stderr were written to my logfile.

This code does it:

do
star -diff -vv f=$dumpdevice -C $dir . 2>>$logfilename
done >>$logfilename

The output of stderr goes to the log file because of the 2>>$logfilename.

The output of stdout goes to the log file because of
do
[..]
done >> $logfilename

Don't ask me why. Sometimes I think that the designers of Bash wrote the interpreter, and discovered afterwards how some command turned out to work.

BTW, why do you export LOGFILE=/root/logs/backup.log? Just LOGFILE=/root/logs/backup.log should be enough for this script. Or maybe I don't understand it at all and that is why I had to use this workaround in my own script anyway.

You can find the entire script here . It is not perfect, but it is useful. It does nice logging of both the events and provides a full list of backed-up files.

jlinkels
 
Old 05-18-2005, 04:30 PM   #9
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
My guess is that dump (and other utilities) may be stupidly calling freopen on devices. In other words, they're not doing the right thing.
 
  


Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting question... Basslord1124 Linux - Networking 2 11-09-2005 06:52 AM
Scripting Question... Darklight451 Linux - Newbie 3 09-23-2004 06:03 PM
Scripting question sujte Linux - General 2 05-24-2004 05:52 PM
Scripting question aikitortoise Linux - Newbie 3 11-14-2002 06:18 PM
New to Scripting question s&j Linux - General 2 06-25-2002 09:27 PM


All times are GMT -5. The time now is 04:26 PM.

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