Mark Rogers wrote:
> Is there a general way, via SSH, to determine the distro I am running on
> any given PC?
> 
> I'm hoping to be able to determine both the distro
> (Ubuntu/Fedora/CentOS/etc) and the version (Ubuntu 6.06/6.10/7.04).

Generally cat /etc/lsb-release will work on such distributions. However,
if you want a way that works everywhere, here is C code under the GPL-2
license, from xchat-xsys.
It won't run as is, but it should provide you with the name of the files
to check. If the code interests you, it is available from:
http://dev.gentoo.org/~chainsaw/xsys/

Regards,
Tony V.

P.S. /etc/lsb-release is not in this version, but will be in version 3

int xs_parse_distro(char *name)
{
	FILE *fp = NULL;
	char buffer[bsize], *pos = NULL;
	
	if((fp = fopen("/etc/lsb_release", "r")) != NULL)
	{
		char id[bsize], codename[bsize], release[bsize];
		strcpy(id, "?");
		strcpy(codename, "?");
		strcpy(release, "?");
		while(fgets(buffer, bsize, fp) != NULL)
		{
			find_match_char(buffer, "DISTRIB_ID", id);
			find_match_char(buffer, "DISTRIB_CODENAME", codename);
			find_match_char(buffer, "DISTRIB_RELEASE", release);
		}
		snprintf(buffer, bsize, "%s \"%s\" %s", id, codename, release);
	}
	else if((fp = fopen("/etc/make.conf", "r")) != NULL)
	{
		char keywords[bsize];
		while(fgets(buffer, bsize, fp) != NULL)
			find_match_char(buffer, "ACCEPT_KEYWORDS", keywords);
		if (strstr(keywords, "\"") == NULL)
			snprintf(buffer, bsize, "Gentoo Linux (stable)");
		else
			snprintf(buffer, bsize, "Gentoo Linux %s", keywords);
	}		
	else if((fp = fopen("/etc/redhat-release", "r")) != NULL)
		fgets(buffer, bsize, fp);
	else if((fp = fopen("/etc/slackware-version", "r")) != NULL)
		fgets(buffer, bsize, fp);
	else if((fp = fopen("/etc/mandrake-release", "r")) != NULL)
		fgets(buffer, bsize, fp);
	else if((fp = fopen("/etc/SuSE-release", "r")) != NULL)
		fgets(buffer, bsize, fp);
	else if((fp = fopen("/etc/turbolinux-release", "r")) != NULL)
		fgets(buffer, bsize, fp);
	else if((fp = fopen("/etc/frugalware-release", "r")) != NULL)
		fgets(buffer, bsize, fp);
	else if((fp = fopen("/etc/debian_version", "r")) != NULL)
	{
		char release[bsize];
		fgets(release, bsize, fp);
		snprintf(buffer, bsize, "Debian %s", release);
	}
	else
		snprintf(buffer, bsize, "Unknown Distro");
	if(fp != NULL) fclose(fp);
	
	pos=strchr(buffer, '\n');
	if(pos != NULL) *pos = '\0';
	strcpy(name, buffer);
	return 0;
}

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Peterboro mailing list
[email protected]
https://mailman.lug.org.uk/mailman/listinfo/peterboro

Reply via email to