The problem is, doing this inside of a loop for a number of hosts means I need to enter my password over and over and over again. I can use expect to feed the password to 'sudo -v', but it doesn't persist outside of the expect section. Inside of expect, supposedly there are variables like $expect_out(buffer) or $expect_out(0,string) but I'm still trying to figure out how to use them.
How can I get my above result without changing anything on the remote host?
Because that will echo the value I want to stout, which doesn't do me any good... the value needs to be available to the script to echo out later. Every other value, which does not require root access, is loaded into a variable. There may be some other mechanism that can accomplish the same end, so I don't want to be fixated on variables.
ETA: You got me steered in the right direction, though! I wound up with:
ssh $host ls /etc/cma.conf >/dev/null 2>&1
if [ "$?" -eq 0 ]; then
if [ -f /tmp/hbss.sh ]; then rm -f /tmp/hbss.sh; fi
cat >/tmp/hbss.sh <<EOF
#!/bin/bash
ssh -tt $host sudo grep CMABuildNumber /etc/cma.conf <<EOS
$SUDOPASS
EOS
EOF
chmod 755 /tmp/hbss.sh
HBSSVER=`/tmp/hbss.sh | grep CMABuildNumber | cut -d'>' -f2 | cut -d'<' -f1`
#if [ -f /tmp/hbss.sh ]; then rm -f /tmp/hbss.sh; fi
fi