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`
do
{
echo "***************************$i***************************************"
sshpass -p 'password' ssh abc@ipaddress “/sbin/ifconfig >> /home/ankush/output.txt”
}
done
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
“ ”
(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).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.