How to add the real hostname in the beginning of Linux cli command
You could run:
sar -p -d 1 1 | sed "s/^/$(hostname) /"
You can do:
sar -p -d 1 1 | sed "s,^,$(hostname) ,"
if you want to prepend hostname to only non-empty lines:
sar -p -d 1 1 | sed -E "s,^(.+),$(hostname) \1,"
An awk version:
sar -p -d 1 1 | awk -v HOSTNAME=$HOSTNAME '{print HOSTNAME " " $0}'
with the -v flag we set the bash $HOSTNAME variable to a variable that awk can reference in its print statement. With $0 we print the entire line
Or on ssh:
ssh user@remote "sar -p -d 1 1 | awk -v HOSTNAME=$HOSTNAME '{print HOSTNAME \" \" \$0}'"