invalid argument in bash script when port is bad

Posted on

Problem :

When I do this command I get an error when there is something wrong with the eth3.

RESC="1234"

RESD="1234"

RESO="1234"

RESC=$(ssh -q vmx@$1 cat /sys/class/net/$2/carrier)

RESO=$(ssh -q vmx@$1 cat /sys/class/net/$2/operstate)

RESD=$(ssh -q vmx@$1 cat /sys/class/net/$2/dormant)

cat: /sys/class/net/eth3/carrier: Invalid argument

cat: /sys/class/net/eth3/dormant: Invalid argument

How can I use the invalid argument inside the RESC and RESD variable?

Solution :

If you want an error output to be expanded in $(...) then you have to redirect the descriptor 2 – stderr to the descriptor 1 – stdout.

RESC=$(ssh -q vmx@$1 cat /sys/class/net/$2/carrier 2>&1)

Leave a Reply

Your email address will not be published. Required fields are marked *