Web lists-archives.com

Re: A "Where am I" routine




On 07/06/18 07:00, Richard Owlett wrote:
On 07/06/2018 07:15 AM, Zenaan Harkness wrote:
On Fri, Jul 06, 2018 at 06:25:43AM -0500, Richard Owlett wrote:
I multi-boot several configurations &/or releases of Debian.
I will run identical test scripts on each.
I want to store the results in a common logging file.

I can set up an appropriate environment with a custom fstab containing:

  # create a common area
  LABEL=owlcommon /home/richard/Documents/tst_common vfat user,rw,umask=000 0 0
  # a dummy mount labeled to show which instance
  LABEL=dummy /home/richard/Documents/where/sda14 ext4 user,ro 0 0


The first statement gives me a directory usable by all.
The second tells me where I am by using:
    ls /home/richard/Documents/where
in any test script.

As I've only one machine, I'm never conscious of it having a host name.
When I do a new install the same string is generally used for both the host name and the partition label - generally a reminder of current purpose.

E.G.
hostname returns "debian-jan13" -- when installed was key information
Partition label is "new-net-inst" -- I didn't install from DVD.
The partition is /dev/sda14 .
Desired information dependent on topic-du-jour.

One file and two commands come to mind:

2018-07-06 18:55:59 dpchrist@po ~
$ cat /etc/debian_version
9.4

2018-07-06 19:07:38 dpchrist@po ~
$ uname -a
Linux po 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux

2018-07-06 19:25:55 dpchrist@po ~/sandbox/debian
$ mount -l | grep 'on / '
/dev/mapper/sda3_crypt on / type btrfs (rw,relatime,ssd,space_cache,subvolid=5,subvol=/) [po_root]


In a shell script, you can assign these values into variables:

2018-07-06 19:29:15 dpchrist@po ~/sandbox/debian
$ cat id_debian
#!/bin/sh
# $Id: id_debian,v 1.3 2018/07/07 02:30:11 dpchrist Exp $
# Simple-minded script for identifying Debian hosts
# Copyright 2018 by David Paul Christensen dpchrist@xxxxxxxxxxxxxxxx
# Public domain

DEBIAN_VERSION=`/bin/cat /etc/debian_version`
UNAME_A=`/bin/uname -a`
MOUNT_L_ROOT=`/bin/mount -l | /bin/grep 'on / '`

2018-07-06 19:30:16 dpchrist@po ~/sandbox/debian
$ /bin/sh id_debian


You can source the above script from another script to obtain the variable values:

2018-07-06 19:32:08 dpchrist@po ~/sandbox/debian
$ cat source_id_debian
#!/bin/sh
# $Id: source_id_debian,v 1.2 2018/07/07 02:32:07 dpchrist Exp $
# Sources 'id_debian' to obtain identification variables
# Copyright 2018 by David Paul Christensen dpchrist@xxxxxxxxxxxxxxxx
# Public domain

. ./id_debian

echo $DEBIAN_VERSION
echo $UNAME_A
echo $MOUNT_L_ROOT

2018-07-06 19:32:10 dpchrist@po ~/sandbox/debian
$ /bin/sh source_id_debian
9.4
Linux po 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux /dev/mapper/sda3_crypt on / type btrfs (rw,relatime,ssd,space_cache,subvolid=5,subvol=/) [po_root]


David