escaping issue with script that uses ssh via sshpass and runs nmap inside ssh server

102 Views Asked by At

Problem is, when using the sshpass command you need to use (apostrophes) in order to input the command. When I try to use nmap, I'm using hostname -I and awk. The awk ‘{print .. ‘ apostrophe clashes with the sshpass apostrophe.

Is there any alternatives or ways to change that?

I want to run:

sshpass -p “pass” ssh -o Strict…=no user@ip ‘ nmap $(hostname -I | awk ‘{print $1}’) ‘
1

There are 1 best solutions below

0
Ivan On

You need to escape $ with \:

sshpass -p “pass” ssh user@ip "nmap \$(hostname -I | awk '{print \$1}')"