LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-04-2010, 12:23 PM   #1
Lufbery
Senior Member
 
Registered: Aug 2006
Location: Harrisburg, PA
Distribution: Slackware 64 14.2
Posts: 1,180
Blog Entries: 29

Rep: Reputation: 135Reputation: 135
Showing command output on the screen while simultaneously logging it.


Hi all,

I'm still learning about bash scripting. Not too long ago, with a lot of help from folks on this forum, I developed the following script to keep Slackware -stable up-to-date:

Code:
#!/bin/bash
#update_slackware.sh
#Note: run this script as root from the local ./patches directory.

#Synchronize the local mirror with the remote mirror.
# The -e and -n switches delete old packages and only
#   download the new ones:
lftp -c "open ftp://my-favorite-mirror/slackware-version/patches/ ; mirror -e -n packages"

#Download the most recent CHECKSUMS.md5 file:
rm -f CHECKSUMS.md5
lftp -c get ftp://my-favorite-mirror/slackware-version/patches/CHECKSUMS.md5

#Check for MD5 checksum errors and exit if some are found.
if grep "\./packages/" CHECKSUMS.md5 | md5sum -c | grep -v OK$
   then echo "Script aborting. Try manually downloading the file(s) listed above"
   exit 1
fi

#Upgrade Slackware with downloaded packages:
echo "No errors found; updating with new packages."
upgradepkg ./packages/*.txz

#Find configuration files that need attention:
echo "Checking for new configuration files:"
find /etc -name "*.new"
I'm happy with this script. I've tested it and it works well. However, I'd like to log the output into a file, but I also want to see it on the screen.

I know I can put:

Code:
>> recent_update_log.txt
after each of the commands above, but is that the best way to log the output? Can I still see the results on the screen as they happen?

I thought I would add something like:

Code:
FILEDATE=$(date +%Y%m%d)
And then something like this after each command:

Code:
lftp whole bunch of stuff >> $FILEDATE_update_log.txt
Am I on the right track?

Regards,

-Drew
 
Old 02-04-2010, 12:30 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
There are probably a few ways to do it, but the first thing that comes to mind is the "tee" command, which is designed to do exactly what you are asking about.
 
Old 02-04-2010, 02:16 PM   #3
Lufbery
Senior Member
 
Registered: Aug 2006
Location: Harrisburg, PA
Distribution: Slackware 64 14.2
Posts: 1,180

Original Poster
Blog Entries: 29

Rep: Reputation: 135Reputation: 135
Awesome! I'll do more research. Thanks.

-Drew
 
Old 02-04-2010, 02:18 PM   #4
gapan
Member
 
Registered: Feb 2007
Posts: 378

Rep: Reputation: 163Reputation: 163
Yes, tee works fine for that
Code:
script.sh 2>&1 | tee script.log
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running command simultaneously tuesday Linux - General 5 04-17-2008 04:28 AM
IS it possible to send command output to a file as well as the screen helptonewbie Programming 6 09-16-2007 01:13 PM
dd 2 output files simultaneously, is it possible? kav Linux - Software 1 07-28-2007 01:39 PM
simultaneously sound output failure Andruha Linux - Hardware 2 03-22-2007 07:29 AM
Is there a way to view all workspaces on one monitor screen simultaneously? Booger Linux - General 4 12-03-2003 08:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:16 PM.

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