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

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I have read up on process substitution before with tee, but that was confusing me. This puts it into an easier context.
-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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.