0

What I want to do is simple enough, but I cannot get it done without several commands. This is what it looks like so far. I'd love to be able to do this in one sloppy looking line that just passes all the commands at once.

# cat /sys/class/scsi_host/host*/device/fc_host:host*/port_name >port
# cat /sys/class/scsi_host/host*/device/fc_host:host*/speed >speed
# cat /sys/class/scsi_host/host*/device/fc_host:host*/port_state >state
# paste -d ' ' port speed state
0x218000e01a0002d2 8 Gbit Online
0x218100e01a2002d2 8 Gbit Online

I've tried to do this with sub shells, variables, etc. The format ends up misaligned, or worse.

# echo "$port_name" "$speed" "$state"
0x218000e01a0002d2
0x218100e01a2002d2 8 Gbit
8 Gbit Online
Online

# paste -d ' ' "$(cat /sys/class/scsi_host/host*/device/fc_host:host*/port_name)" "$(cat /sys/class/scsi_host/host*/device/fc_host:host*/speed)"
paste: 0x218000e01a0002d2
0x218100e01a2002d2: No such file or directory
gNU.be
  • 1,937
  • 2
  • 10
  • 9

2 Answers2

2

Instead of command substitution, try process substitution:

paste -d ' ' <(cat /sys/class/scsi_host/host*/device/fc_host:host*/port_name) \
             <(cat /sys/class/scsi_host/host*/device/fc_host:host*/speed) \
             <(cat /sys/class/scsi_host/host*/device/fc_host:host*/port_state)
chepner
  • 497,756
  • 71
  • 530
  • 681
  • I have read up on process substitution before with tee, but that was confusing me. This puts it into an easier context. – gNU.be Mar 06 '13 at 16:07
-1

What about this?

for i in /sys/class/fc_host/host*; do (cd $i; echo -e "$(cat port_name)\t$(cat port_state)\t$(cat speed)"); done