[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"
$(grep …)
gets expanded locally, apparently it returns an empty string. Depending on where you want to expand it, you should double-quote or single-quote (or escape). After the local shell removes quotes it does interpret, the resulting command string will be interpreted again on the remote side. At this point it should contain quotes to be interpreted there. So you need at least two levels of quoting/escaping. For now I'm not sure if you want$()
to work locally. How about&&
? Is</dev/null
forssh
or forsudo
? In general: what is expected?