Solved

UNIX Script Help

Posted on 2014-01-30
8
198 Views
Last Modified: 2014-02-04
Hello,

I need some help in writing a shell script, So if i have

echo "Enter the disks name: "
read DISK

Then what ever disk name I type in is assigned to the variable DISK.

But if I have a file, which has disks
#cat file
hdisk1
hdisk2
hdisk3
hdisk4

So how do i script to "read" the disks in a file...??
0
Comment
Question by:aanya247
8 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 39822219
cat > Q_28352688.sh << END
echo "Enter the disks name: "
read DISK
echo $DISK
END

sh Q_28352688.sh < file

for D in `cat file` ; do echo $D | sh Q_28352688.sh ; done
0
 

Author Comment

by:aanya247
ID: 39822382
Thanks OZO for your response....

I didnot quite understand, What is Q_28352688.sh, I only have one file 'file' in which i have disks. I am sorry I am still in a learning phase..
0
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 100 total points
ID: 39822420
It's called a here document and basically inserts into Q_28352688.sh whatever follows until it reaches END.

HTH,
Dan
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 84

Expert Comment

by:ozo
ID: 39822442
I don't know the name of your shell script or what else you have in it,
so for illustrative purposes, I created one in order to demonstrate some ways to read DISK from file
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39822597
Easier to do

cat file | xargs yourscript.sh
0
 
LVL 84

Expert Comment

by:ozo
ID: 39822627
xargs yourscript.sh
might work with
DISK=$1
but not with
read DISK
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39831906
the `cat ...` method may fail with large lists (something like 2M which is not *that* much) since a command line can't have arbitrary length.

Strange that nobody came up with while read (please don't reopen the question):

cat file | while read DISK; do
  echo $DISK
done

Open in new window

0
 

Author Comment

by:aanya247
ID: 39833155
Thank you...
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question