LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-12-2008, 11:55 PM   #1
khairil
LQ Newbie
 
Registered: May 2005
Distribution: gentoo
Posts: 23

Rep: Reputation: 15
reformat output of cat /proc/scsi/scsi


hello,

if i run command
Code:
mybox:~> cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: MATSHITA Model: DVD-RAM UJ-860H  Rev: 1.02
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: FUJITSU MHY2120B Rev: 890B
  Type:   Direct-Access                    ANSI  SCSI revision: 05
i'm using php to iterate all scsi devices in my system, how to format the output of cat /proc/scsi/scsi to return scsi host and vendor in the following format (similar to 'lsscsi' command);
Code:
0 0 0 0    MATSHITA DVD-RAM UJ-860H
2 0 0 0    ATA      FUJITSU MHY2120B
it is easy if i'm on linux 2.6 as i have 'lsscsi' which output;
Code:
khairil@box4:~/drivers> lsscsi
[0:0:0:0]    cd/dvd  MATSHITA DVD-RAM UJ-860H  1.02  /dev/sr0
[2:0:0:0]    disk    ATA      FUJITSU MHY2120B 890B  /dev/sda
thx.

Last edited by khairil; 01-13-2008 at 12:02 AM.
 
Old 01-13-2008, 01:10 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
<?php
$cmd = `cat /proc/scsi/scsi`;
$patternhost = "/Host:\s+scsi(\d+)\s+Channel:\s+(\d+)\s+Id:\s+(\d+)\s+Lun:\s+(\d+)/Ums";
$patternvendor = "/Vendor:(.*)\s+Model:(.*)\s+Rev.*/Ums";
preg_match_all($patternhost,$cmd,$hostmatch);
print_r($hostmatch);
preg_match_all($patternvendor,$cmd,$vendormatch);
print_r($vendormatch);
?>
I leave it to you to grab the array elements and format them to your needs.
 
Old 01-13-2008, 01:50 AM   #3
khairil
LQ Newbie
 
Registered: May 2005
Distribution: gentoo
Posts: 23

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ghostdog74 View Post
Code:
<?php
$cmd = `cat /proc/scsi/scsi`;
$patternhost = "/Host:\s+scsi(\d+)\s+Channel:\s+(\d+)\s+Id:\s+(\d+)\s+Lun:\s+(\d+)/Ums";
$patternvendor = "/Vendor:(.*)\s+Model:(.*)\s+Rev.*/Ums";
preg_match_all($patternhost,$cmd,$hostmatch);
print_r($hostmatch);
preg_match_all($patternvendor,$cmd,$vendormatch);
print_r($vendormatch);
?>
I leave it to you to grab the array elements and format them to your needs.
thx a lot ghostdog74! it helps me a alot!
 
  


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
non-root access to /proc/scsi/scsi greenRavens Linux - Software 3 10-19-2006 02:44 PM
Hotplug SCSI scanner or How to write to /proc/scsi/scsi from within a shell script. samac Linux - Hardware 1 08-30-2004 02:28 PM
Error editing /proc/scsi scsi file Thaidog Linux - Newbie 2 08-26-2004 08:19 AM
Some info about '/proc/scsi/scsi' and '/dev' C.Loko Slackware 4 11-27-2003 12:30 PM
allow non root users add devices to /proc/scsi/scsi ? ewto Linux - Newbie 5 10-14-2003 11:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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