HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Get data from client using SSH in shell script (http://www.howtoforge.com/forums/showthread.php?t=53887)

waiwai 24th August 2011 07:50

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.

Mark_NL 24th August 2011 15:20

Code:

ssh -q <server> "hostname; uname -a"


All times are GMT +2. The time now is 07:48.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.