I have been tweaking this for quite a bit and I am stuck with a strange output stream and no result. Basically, I'm trying to find certain ssh devices on our expansive network that have a specific password and processor. Here is the script:
#/bin/bash
for i in 54
do
for j in 1 13 14 15
do
out=$(expect -c "spawn /usr/bin/ssh [email protected].$i.$j cat /proc/cpuinfo | grep MyString
expect {
-re \".*Are.*.*yes.*no.*\" {
send \"yes\n\"
exp_continue
}
\"*?assword:*\" {
send \"mypasswd\"
send \"\n\"
exp_continue
}
}")
if [["$out" != ""]]
then
echo "10.2.$i.$j" >> rpiout.txt
fi
done
done
The ssh command works by itself, just fine. Also, the expect script works fine. ALSO, if I insert an "echo $out" right before the "if [[...]]" statement, I get the expected output from the SSH command. Trying to write the file, however, I get this output to the command line and NO log file...:
./check.sh: line 19: [[spawn /usr/bin/ssh some_guy:@10.2.54.1 cat /proc/cpuinfo | grep MyString
some_guy:@10.2.54.1's password:
Permission denied, please try again.
some_guy:@10.2.54.1's password:
Permission denied, please try again.
some_guy:@10.2.54.1's password:
: No such file or directoryy,password).
./check.sh: line 19: [[spawn /usr/bin/ssh some_guy:@10.2.54.13 cat /proc/cpuinfo | grep MyString
some_guy:@10.2.54.13's password:
: No such file or directory
./check.sh: line 19: [[spawn /usr/bin/ssh some_guy:@10.2.54.14 cat /proc/cpuinfo | grep MyString
some_guy:@10.2.54.14's password:
: No such file or directory
: No such file or directoryawn /usr/bin/ssh some_guy:@10.2.54.15 cat /proc/cpuinfo | grep MyString
The first one asking for the password 3 times is correct (because it is not one of the target devices). The second 2 are non-existant IP devices, but the last 2 should return a positive result.
Note that in the "error" "./check.sh: line 19: [[spawn...", line 19 is the one that starts with "if [[...".
Any help to get me out of this mess is greatly appreciated!!
#!/bin/bash -vx?