I have more than 60 to 80 systems running Ubuntu. Some of them are with version 8.04 and some of them are with latest version 10.10. Now we are in the process of upgrading all older Ubuntu version to a newer version. It is difficult to switch on every Ubuntu system and taking notes of older Ubuntu version and then upgrade. I have IP addresses of all these machines in a text a file. So I am looking for a simple bash script which will automate the task. I am expecting the output would look like this: ubuntu 10.04 ubuntu 8.04 ubuntu 8.10

and so on.. Can anyone help me?


You can get the Ubuntu version using

$ lsb_release -s -d
Ubuntu 10.04.1 LTS

If you want to automate that, write a Bash script that reads list of hosts from stdin and executes the command over SSH. Something like

while read host; do
   echo -n "$host: "
   ssh "$host" lsb_release -s -d < /dev/null

If you have one common user account on all the machines you want to connect to then this should be what you are looking for

while read host; do
   echo -n "$host: "
   ssh "$RUSER@$host" lsb_release -s -d < /dev/null

Save it as versions.sh, remembering to make it executable (chmod a+x versions.sh), and execute

$ versions.sh < ips.txt
  • I want the output for all the 80 systems running ubuntu by executing single command or by simple script.I know to find the ubuntu version in a single machine. – karthick87 Mar 31 '11 at 14:59
  • I was already updating my answer when you posted the comment. Hope that helps. – Adam Byrtek Mar 31 '11 at 15:06
  • btw, $ip may contain user@host information. – antivirtel Mar 31 '11 at 15:47
  • Yes, it can be anything accepted by ssh, as long as it's space separated. – Adam Byrtek Mar 31 '11 at 21:07
  • Do you want me to make it as bash script?And $IP should contain ip addresses of all the machines right? – karthick87 Apr 1 '11 at 9:58

Assuming they are running SSH servers, you could try to guess Ubuntu versions based on the package version of SSH:

$ nc IP.IP.IP.IP 22
SSH-2.0-OpenSSH_5.5p1 Debian-4ubuntu5

Current versions of openssh are listed in Launchpad https://launchpad.net/distros/ubuntu/+source/openssh:

openssh | 1:4.2p1-7ubuntu3.5 | dapper-updates/main
openssh | 1:4.7p1-8ubuntu3   | hardy-updates/main
openssh | 1:5.1p1-6ubuntu2   | karmic/main
openssh | 1:5.3p1-3ubuntu6   | lucid-updates/main
openssh | 1:5.5p1-4ubuntu5   | maverick-updates/main
openssh | 1:5.8p1-1ubuntu2   | natty/main

So in my above example, 5.5p1 with a Debian version of -4ubuntu5 looks to be an Ubuntu 10.10 Maverick system.

Some servers may have "DebianBanner no" in their /etc/ssh/sshd_config file, but the upstream version of OpenSSH is still visible which is sufficient to identify the system still (each release of Ubuntu so far has a different upstream version of OpenSSH).

  • I like this - this is potentially the least labour-intensive solution. It does not require you to set up anything on the 80 hosts. – DrSAR Apr 13 '11 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.