20

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:

172.29.34.40 ubuntu 10.04
172.29.34.41 ubuntu 8.04
172.29.34.42 ubuntu 8.10

and so on.. Can anyone help me?

2 Answers 2

30

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

#!/bin/bash
while read host; do
   echo -n "$host: "
   ssh "$host" lsb_release -s -d < /dev/null
done

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

#!/bin/bash
RUSER="username"
while read host; do
   echo -n "$host: "
   ssh "$RUSER@$host" lsb_release -s -d < /dev/null
done

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

$ versions.sh < ips.txt
13
  • 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, 2011 at 14:59
  • I was already updating my answer when you posted the comment. Hope that helps. Mar 31, 2011 at 15:06
  • btw, $ip may contain user@host information.
    – antivirtel
    Mar 31, 2011 at 15:47
  • Yes, it can be anything accepted by ssh, as long as it's space separated. Mar 31, 2011 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, 2011 at 9:58
3

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

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

1
  • 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, 2011 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .