SSH cannot pass specific commands to the remote router

I am trying to run the command "iwlist wlan0 scan" on a remote router in my network. I have tried the following SSH commands

ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 iwlist wlan0 scan
ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 "iwlist wlan0 scan"
ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 `iwlist wlan0 scan
ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 \`iwlist wlan0 scan\`
ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 \"iwlist wlan0 scan\"*

but all of these commands lead to the following error:

ash: iwlist: not found

However when I am actually logging into the router using the command

ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 

and I run "iwlist wlan0 scan" it works and I can see the list of surrounding access points. This means that "iwlist" is actually available on my router but I cannot pass it to the router correctly. Also when I run the following commands

ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 ls
ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 pwd 
ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 uname -n

They work perfectly fine while if I run

ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 route -n 

it does not work but again if I log into the router and run "route -n" I will get the result. So I guess SSH is choosing which one of my commands to pass and which one not to pass. Any ideas on how to fix this?

Thanks,

Upvotes: 1

Views: 86

Answers (1)

AMADANON Inc.
AMADANON Inc.

Reputation: 5929

You may not have the same environment variables (e.g. PATH) set when you log in, vs. running a command without logging in.

Try the following: find out where the commands are. You may be able to run which route, if you're lucky (depending on how much of unix is on the router).

Once you find the full path of the command, try specifying that. For example, if which route shows /sbin/route, then try replacing route in your command with /sbin/route - e.g. ssh -o IdentityFile=~/Dropbox/ALI/id_rsa -l root 172.20.125.162 /sbin/route -n

Upvotes: 1

Related Questions