In my environment there are about 1000 production servers. Direct root login is disabled on all servers. There is one user "abc" which has sudo access. We login to each computer using "abc" and then sudo su - to get root access.

Please note that I am running this script on a Ubuntu machine and connecting to a RHEL machine.

There is a requirement to know hostname and OS version of each remote server IP.

So I made a script which will connect with remote system and execute a command and saves output in a local file.

Script which I managed to create is as below:

for i in `cat test1` 
    echo "***************************$i***************************************" 
    sshpass -p 'password' ssh abc@ipaddress “/sbin/ifconfig >> /home/ankush/output.txt”

It connects to all computers IP address present in test1 file and executes, but doesn't execute ifconfig command on the remote system.

On execution it is giving error as:

***************************ip address***************************************
bash: “/sbin/ifconfig: No such file or directory
  • See this question: unix.stackexchange.com/questions/145447/… – Johan Myréen Nov 13 '16 at 6:38
  • It may be an artifcact of your badly formatted post, but it appears you used the 'curly' double-quote characters “ ” (used/replaced automatically by some web/HTML software and most Microsoft software) not the old-style 'straight' double-quote " which (along with straight single quote or apostrophe ') is the only one that works in Unix shells (and many other Unix programs). – dave_thompson_085 Nov 13 '16 at 9:50
  • 2
    ifconfig is not the right tool anyway to find out hostname or os-version. Your script is broken in may ways. I wonder that you have root access to 1000 systems. Maybe you should hire a sysadmin who knows at least some basics. – rudimeier Nov 13 '16 at 10:40
  • With such requirements (hostnames/ip lookup), it may be interesting for you to give a look at Ansible (github.com/ansible/ansible) – SYN Nov 13 '16 at 18:21

There is a requirement to know hostname,os version of each remote server ip.

There is an excellent tool for that called nmap. It is available for Ubuntu, link here.


nmap -sP 192.168.1.*

Here's another link that might be useful.


Ansible can do that (and more) for you :

ansible remotehost -m setup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.