LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 02-22-2013, 03:36 AM   #1
sluge
Member
 
Registered: Dec 2006
Location: Russia,52
Posts: 97

Rep: Reputation: 6
Question How to shows incessantly output in bash?


Hello!
I have a code in my bash script

Code:
OUTPUT=""`yum update`
echo $OUTPUT
echo $OUTPUT >> mylogfile
Code:
yum update
is a very long command and without my script it always output something to console, but in my script it starts, for the long time nothing outputs and after a while outputs a lof of data.
Is any way in my script to output data as soon as it is available, but not all data in the same time after long waiting?
 
Old 02-22-2013, 03:49 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 650

Rep: Reputation: 268Reputation: 268Reputation: 268
No experience with yum, but do you mean something like this?

Code:
yum update | tee mylogfile
 
Old 02-22-2013, 03:55 AM   #3
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Hi sluge,

Correct me if I'm understating you wrong.

Are you trying to redirect the output of "yum update" command to a file named mylogfile ???
 
Old 02-22-2013, 06:16 AM   #4
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Slack14_64_Multilib
Posts: 2,721
Blog Entries: 3

Rep: Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627
yum is probably waiting for a Y/N response.

'yum update -y' will answer in the affirmative inside the script. This may lead to undesirable updates being installed.
 
Old 02-22-2013, 09:19 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,692

Rep: Reputation: 425Reputation: 425Reputation: 425Reputation: 425Reputation: 425
The problem you see is buffering - you can't get any output until all of it is provided...

I use the "script" utility to record activity (both output and input).
 
Old 02-22-2013, 09:45 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,526
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
...besides all of that when the OP runs 'yum -y update' Yum is configured log to /var/log/yum.log by default so echoing $OUTPUT to some custom file makes no sense at all.
 
Old 02-22-2013, 01:14 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,692

Rep: Reputation: 425Reputation: 425Reputation: 425Reputation: 425Reputation: 425
That log is good... but it only shows what yum did, not what it didn't, or the error messages that occurred along the way. Things like mirror fails, timeouts, conflicts...
 
Old 02-23-2013, 06:44 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,526
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
The point of my post is one should know the system before deciding to re-invent the wheel. Conflicts will obviously always remain an issue that requires human intervention, mirror fails aren't fatal unless none of the mirrors work, timeouts aren't interesting unless the updates won't be fetched from that or another mirror. If verbose or error reporting is required the OP should look at yum-updatesd first.
 
Old 02-23-2013, 07:19 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,692

Rep: Reputation: 425Reputation: 425Reputation: 425Reputation: 425Reputation: 425
What is uninteresting to you might be very interesting to someone else.

ESPECIALLY when they ask for the error message that was generated...

Hence, the use of "script" to record everything.
 
Old 02-23-2013, 08:19 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,526
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
If the OP really finds that "very interesting" then he could have recorded stdout and stderr with something like
Code:
/usr/bin/yum -e10 -y update >> /path/to/log/file 2>&1
Why would it be advantageous or necessary to use 'script' for just that?..
 
Old 02-23-2013, 08:37 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,692

Rep: Reputation: 425Reputation: 425Reputation: 425Reputation: 425Reputation: 425
Because that doesn't record the input. What answers to prompts were done?

Using redirection works, but assuming all yes responses is not necessarily complete.

The other advantage script has is that it will make a complete log of the session - so anything done to correct/alter the situation during install (such as doing a "yum clean", killing any stuck processes/locks may also be significant.
 
Old 02-26-2013, 01:00 AM   #12
sluge
Member
 
Registered: Dec 2006
Location: Russia,52
Posts: 97

Original Poster
Rep: Reputation: 6
Hello, thanks for you answers

So, for the first, log in my script is wtiring using special function func_log:

func_log "My log"

So, tee is not actual here.
 
  


Reply

Tags
bash


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server restarted but uptime shows different output sampappachan_nyc Linux - Server 3 10-10-2011 03:32 PM
[SOLVED] Bash; awk or sed output to variable: how keep newline at end of each output line porphyry5 Programming 3 06-10-2011 05:50 PM
sar output shows different CPU utilization.. vikas027 Linux - Server 2 07-16-2009 10:58 PM
cupsaddsmb shows no output lrt Linux - Server 1 06-30-2008 03:08 PM
mplayer xv output shows blank window on secondary monitor idris Linux - Hardware 0 09-12-2004 10:48 AM


All times are GMT -5. The time now is 03:36 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