Skip to main content
Here-docs, ssh and command substitutions are a difficult mix
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << E7
        #sudo rm -r SoundEye.zip
        echo'echo "MAC=$(ip link show wlan0eth0 | awk ''\''/^ *link/ {print $2}''\'')"
       "; echo "DATE=$(date)"
E7"')

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << E7
        #sudo rm -r SoundEye.zip
        echo "MAC=$(ip link show wlan0 | awk '/^ *link/ {print $2}')"
        echo "DATE=$(date)"
E7)

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" 'echo "MAC=$(ip link show eth0 | awk '\''/^ *link/{print $2}'\'')"; echo "DATE=$(date)"')

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.

deleted 2 characters in body
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << 'E7'E7
        #sudo rm -r SoundEye.zip
        echo "MAC=$(ip link show wlan0 | awk '/^ *link/ {print $2}')"
        echo "DATE=$(date)"
E7)

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << 'E7'
        #sudo rm -r SoundEye.zip
        echo "MAC=$(ip link show wlan0 | awk '/^ *link/ {print $2}')"
        echo "DATE=$(date)"
E7)

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << E7
        #sudo rm -r SoundEye.zip
        echo "MAC=$(ip link show wlan0 | awk '/^ *link/ {print $2}')"
        echo "DATE=$(date)"
E7)

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.

Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

Since you want to retrieve output generated in your ssh session, you could try to store the output of the ssh session in total in a shell variable and then parse that output to extract the relevant bits.

The following should work. It will prepend the relevant lines with "start tags" to distinguish them from other messages (e.g. motd) that may be produced:

raw_output=$(sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << 'E7'
        #sudo rm -r SoundEye.zip
        echo "MAC=$(ip link show wlan0 | awk '/^ *link/ {print $2}')"
        echo "DATE=$(date)"
E7)

mac_add=$(sed -E '/^MAC=/s/^[^=]+=//;t;d' <<< "$raw_output")
timing=$(sed -E '/^DATE=/s/^[^=]+=//;t;d' <<< "$raw_output")

The relevant values are then extracted via sed calls (by searching for and replacing the respective <tag>= part at beginning of the relevant lines with "nothing") and stored in bash variables local to your script.