View Single Post
  #1  
Old 24th August 2011, 07:50
waiwai waiwai is offline
Junior Member
 
Join Date: Aug 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get data from client using SSH in shell script

Currently I have 1 server and 2 slaves, I wan to get hostname and version from slaves using SSH command.

Code:
while read line
do
#read hostname
#read line
num=0
ssh -t -t ${line} < cmd > test2.txt
num=1
if [ $num -eq 1 ]
then
ssh -t -t ${line} < cmd >> test2.txt
fi
done
echo "done"
exit 0
the code is work fine. but I'm kinda dissapointed on the results. I got what I wan but just too much.

[RESULT]Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-generic i686)

* Documentation: https://help.ubuntu.com/

206 packages can be updated.
59 updates are security updates.

Last login: Tue Aug 23 20:11:02 2011 from 10.0.0.1

echo hostname = `hostname`
echo version = `uname -a`
exit

^[]0;ccc@ubuntu: ~^Gccc@ubuntu:~$ echo hostname = `hostname`
hostname = ubuntu
^[]0;ccc@ubuntu: ~^Gccc@ubuntu:~$ echo version = `uname -a`
version = Linux ubuntu 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UT$
^[]0;ccc@ubuntu: ~^Gccc@ubuntu:~$ exit
logout
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-generic i686)

* Documentation: https://help.ubuntu.com/

206 packages can be updated.
59 updates are security updates.

Last login: Tue Aug 23 20:13:59 2011 from 10.0.0.1

echo hostname = `hostname`
echo version = `uname -a`
exit

^[]0;ccc@ubuntu: ~^Gccc@ubuntu:~$ echo hostname = `hostname`
hostname = ubuntu
^[]0;ccc@ubuntu: ~^Gccc@ubuntu:~$ echo version = `uname -a`
version = Linux ubuntu 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UT$
^[]0;ccc@ubuntu: ~^Gccc@ubuntu:~$ exit
logout
[/RESULT]

How to display the data I wan?What I wan is only hostname and version. I wan to delete the Welcome to ubuntu, those echo stuff..

Thanks.
Reply With Quote
Sponsored Links