Linux Shell Script To Find Kernel Version From Multiple Servers

linux shell script

Linux shell script that will login to server via ssh and get kernel version via uname -r command. List of all the servers are in server_list.txt file, script will take name by name and try to ssh with the root user and run uname -r command. Output will be written to variable and after into file with servername. This script helps system administrator who manage large linux servers , to take reports of what linux versions running. Here I have used uname -r but you can edit and use your own command as per your requirements.

Linux Shell Script

#!/bin/bash
#we user variable serverlist to keep there path to file with server names
serverlist='server_list.txt'
#we write in variable all server list
servers=`cat $serverlist`
#we use variable result to keep there path to file with result
result='result.txt'

#this print header to file with resilt using \t\t to add 2 tab symbols
echo -e "Servername \t\t kernel version"> $result
#this get each line of serverlist one by one and write to server variable
for server in $servers
do
#this login to server by ssh and get uname -r
kernel=`ssh root@${server} "uname -r"`
#this write server name and kernel version separated by 2 tab to result file
echo -e "$server \t\t $kernel" >> $result
#end of for loop.
done

server_list.txt file
# cat server_list.txt
dev
web1
svn

Shell Script Output

./kernel_version.sh
centos_node1@bobbin:~/Documents/Work/Bobbin$ cat result.txt
Servername kernel version
dev 3.3.8-gentoo
web1 3.2.12-gentoo
svn 3.2.12-gentoo

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

1 Comment