0

[edit] per comment #1: more code, less description

Why doesn't this work as expected? ie: i want to :

  • ssh to a bunch of remote hosts in a loop (hence the </dev/null)
  • check if a setting is present in (the remote) rc.local (with grep)
  • if not then add it (with sed)

fail.sh

#!/bin/bash
targetHostList="
pizerocam0
pizerocam1
pizerocam2
pizerocam3
"
while IFS= read -r targetHost;do
    [[ -z $targetHost ]] && continue
    ssh -q $targetHost "[[ -f /etc/rc.local && -z $(grep -o '/usr/bin/tvservice -o' /etc/rc.local) ]] && sudo sed -Ei 's/exit\ 0/\/usr\/bin\/tvservice\ \-o \#\ disable HDMI\n\nexit\ 0/' /etc/rc.local"
done<<<"$targetHostList"
BETLOG
  • 21
  • 4

1 Answers1

1

[SOLVED] Thanks Kamil! I just needed to see it. Knew it was what I wanted immediately. I'm sure i've done this before and just forgotten how.

SOLVED.sh

#!/bin/bash
targetHostList="
pizerocam0
pizerocam1
pizerocam2
pizerocam3
"
while IFS= read -r targetHost;do
    [[ -z $targetHost ]] && continue

ssh -q $targetHost bash <<'EOF' [[ -f /etc/rc.local && -z $(grep -o '/usr/bin/tvservice -o' /etc/rc.local) ]] && sudo sed -Ei 's/exit\ 0//usr/bin/tvservice\ -o #\ disable HDMI\n\nexit\ 0/' /etc/rc.local EOF

done<<<"$targetHostList"

BETLOG
  • 21
  • 4