Thanks Panyam that works,
But I would like to use this with a script If you could help me to create such script.
1) Run command "server1# rsh server2 df -k /tmp" by mentioning it in script.
2)Script will use list of server from file "List.txt" exist under /tmp directory of server1 3) Will re-direct the output to >> "/tmp/output.txt" file
I guess by using while loop we can do it, but dont know the path/way to move ahead.
---------- Post updated at 03:19 AM ---------- Previous update was at 03:02 AM ----------
#!/bin/bash
# set -vx
while read OPTIONS SERVER
do
echo "$SERVER"
ssh "$OPTIONS" "$SERVER" <<-EOF
df / /tmp /any
EOF
done < /tmp/List.txt > /tmp/output.txt
It is using keyless ssh login, as bipinajith proposed. Fiddling around with passwords in a script is usually discouraged. If you need to use rsh, you may need to tweak above a bit.
Thanks Rudic, that is nearly to what I am seeking for. Some pending are like,
1) I have approx 500 server for which space needs to be calculated.
2) And these server does not have setup ssh-keys as required.
3) To setup ssh-keys on these many servers is tough task.
4) Any other way to get these details without setup ssh-keys and giving password.
I firmly believe that it is easier to once set up keys on 500 servers than to supply passwords every time you run that script (collecting 500 servers' passwords in a file is highly discouraged!).
A side effect to keyless setup would be that from then on, you can easily login to any of those servers interactively without password.
@RudiC:
Your script does not work. Should be either
while read SERVER
do
echo "$SERVER"
ssh -x "$SERVER" /bin/sh << EOF
df / /tmp /any
# eventually more commands
EOF
done < /tmp/List.txt > /tmp/output.txt
or
while read SERVER
do
echo "$SERVER"
ssh -nx "$SERVER" '
df / /tmp /any
# eventually more commands
'
done < /tmp/List.txt > /tmp/output.txt
Tip: if you have more than 50 systems to monitor, then install "Xymon" (earlier named "BigBrother" and "Hobbit").
It has a Web page with green/yellow/red self-clearing alerts, drill-down by mouse-click, and provides alert history and graphical history, availability reports, trend analysis.
Well, it worked exactly as given when I tested it on some of the servers I have access to, admittedly linux systems. And it does right now, testing again.
On the other hand, it was meant as a direction indicator for the requestor to develop his or her own script.
You are right, your solution should work too.
It runs an interactive login shell but without a terminal.
If .profile etc. are not broken, it works nevertheless.
[root@server1:/]#
#-> ssh john@server2 df -k /tmp
The authenticity of host 'server2 (XX.XX.XX.XX)' can't be established.
RSA key fingerprint is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server2' (RSA) to the list of known hosts.
Password:
/tmp (xxxxxxx ) : 11444928 total allocated Kb
11386216 free allocated Kb
58712 used allocated Kb
1 % allocation used
[root@server1:/]#
#->
That is fine, thanks for suggestion and support.
As I have large number of existing server which doest not have ssh key setup. As I tried to check on some server but it asked for password.
Is there any other way to perfrom this without asking for password ?
Thanks to all for their support, still seeking for some parameter by which I can pass the Password and Yes via script and do not required to put it manually.