Reputation: 987
I am trying to check whether a certain package is installed on remote machine in bash script.
If I execute the following statement on the machine itself the result is 1 (installed) in file check.txt, which is correct:
dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed" > /home/someuser/check.txt
However, if I execute the same command in SSH session, the result is always 0.
Can somebody explain why and how to correct this?
Thank you.
#!/bin/bash
ADDRESS=SOMEUSER@$SOMESERVER
function run {
ssh $ADDRESS /bin/bash $@
}
run << SSHCONNECTION
dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed" > /home/someuser/check.txt
SSHCONNECTION
Upvotes: 0
Views: 368
Reputation: 14046
You need to escape the $
character:
dpkg-query -W -f='\${Status}' nano 2>/dev/null | grep -c "ok installed" > /home/someuser/check.txt
Upvotes: 1