LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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
  Search this Thread
Old 05-09-2008, 01:47 PM   #1
Echo Kilo
Member
 
Registered: Jul 2004
Distribution: Ubuntu - Debian Based
Posts: 242

Rep: Reputation: 30
Shell Scripting Question


Is this the right place for this?

I would like to know how to run a command and pipe the output AND see the output.

For example, when I run:

sudo yum update, I want to be able to interact b/c it asks for password and prompts to continue, but I would also like to pipe the results to a file.
 
Old 05-09-2008, 01:58 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Look up the 'tee' command, and you will also want to use a 'bash redirect' (the > or >> symbols) to direct to the file.
 
Old 05-09-2008, 05:16 PM   #3
Echo Kilo
Member
 
Registered: Jul 2004
Distribution: Ubuntu - Debian Based
Posts: 242

Original Poster
Rep: Reputation: 30
thank you.

If the command I'm running in the script requires a response and I want to say N (for No), How do I get a script to respond with that automatically?
 
Old 05-09-2008, 05:32 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

This is starting to look like homework...... which we won't do for you. We will give pointers and tips if you post the answers you came up with/tried yourself.
 
Old 05-10-2008, 11:13 PM   #5
Echo Kilo
Member
 
Registered: Jul 2004
Distribution: Ubuntu - Debian Based
Posts: 242

Original Poster
Rep: Reputation: 30
I wish it was homework! And, I wish I had time for a class on this. I understand why it loooks that way, but I've not got the resources to take a class nor time to master this. I appreciate your assistance and value your responses.

Anyhow, I'm trying to get the available updates on all systems on the network and throw them into a report. I've got it running on a single box and I really don't know how to get the script to respond with a "No". My next step will be to get this to sign onto each system automatically.


#!/bin/bash
##
CNT=1
until [ $CNT -eq 10 ]
do IP=192.168.1.$CNT
REMHOST=`ssh root@$IP -C hostname`
echo "Host $REMHOST at IP $IP returned the following result:"
ssh root@$IP -C yum update | tee list_of_updates
CNT=`expr $CNT + 1`
done
 
Old 05-11-2008, 05:08 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

This indeed looked a lot like homework, sorry if I offended you in any way.

Anyway:

The yes command can possibly be uesd. It is possible to change the default output, which is y, to anything you need/want.

yes No will output a string of No's.

yes No | commandthatneedsinput | .... | ....

Hope this helps.
 
  


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
I have a shell scripting question bartock Linux - General 5 03-06-2008 03:46 PM
shell scripting question angelofhope Linux - Software 5 08-22-2007 05:18 PM
Shell Scripting Question Komelore Programming 2 02-28-2007 08:16 PM
shell scripting question bhert Linux - General 2 01-29-2007 09:55 PM
Shell scripting question. dragin33 Linux - General 2 08-11-2004 06:17 PM


All times are GMT -5. The time now is 11:09 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration