LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 08-28-2007, 10:46 AM   #1
wendtbd
LQ Newbie
 
Registered: Aug 2006
Posts: 14

Rep: Reputation: 0
Question Bash Script Help


I am trying to get a script to work but am getting stuck on my for loop...

scsi_info.log

2 0 2 42
3 0 2 42
0 0 2 25
0 0 2 33
1 0 2 33
2 0 2 28
3 0 2 28

for i in `cat scsi_info.log`;do cat $i;done

This output gives me all the numbers listed in the file scsi_info.log but lists them on individual lines instead of one line.

Ultimately I would like to run the command below in a script;

echo "scsi remove-single-device 2 0 2 42" >/proc/scsi/scsi
echo "scsi remove-single-device 3 0 2 42" >/proc/scsi/scsi
Etc...

So my loop looks like this;

for i in `cat scsi_info.log`;do echo "scsi remove-single-device $i" >/proc/scsi/scsi;done

However since $i outputs each individual number this command fails.

Anyone have any suggestions on how to correct this?

Thanks
Barrett
 
Old 08-28-2007, 10:58 AM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
try something like this:
Code:
cat scsi_info.log | while read line; do 
    echo "scsi remove-single-device $line" >/proc/scsi/scsi;
done
| while read i; do ..... $i; done; will store each line in i
 
Old 08-28-2007, 11:10 AM   #3
wendtbd
LQ Newbie
 
Registered: Aug 2006
Posts: 14

Original Poster
Rep: Reputation: 0
That worked great, thanks for the quick reply
 
  


Reply



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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 06:51 AM
Bash script hangs upon starting another script in the background masea2 Linux - Software 4 11-13-2006 05:18 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 08:36 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
Open Source Consulting | Domain Registration