Script required

Hey All,
I am seeking for the script which will do as follows,

1) Login on one Unix server "Server1"
2) Want to access other Unix server "Server2", and want to get the information as, on one go.

df -k /tmp
df -k /
df -k "any file system"

3) Re-direct the output to "space.txt" on "Server1"

Appologies for such query, I dont know would it work or not as I am new in Unix scripting.

Appreciate the soonest support.

Regards,
R.Kodan

Search on "remsh".

1 Like

You can also use ssh for executing commands on a remote machine.

Syntax:

ssh [user@]hostname [command]

Note that this approach will work without issuing password only if you have setup ssh-keys

In case it is not setup, here is a page that explains how to setup ssh-keys

1 Like

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 ----------

Thanks Bipinajith

You may want to try sth like

#!/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.

1 Like

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.

Please suggest.

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.

1 Like

@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 ?

The only way to do password less authentication is to configure ssh-keys.

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.