Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 02-11-2014, 12:33 PM   #16
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347

Sorry for the long delay (I'm 74 yr.s old so a "minor" cold, isn't). I'll need to look at your script a bit longer, but, to start with, a minor quibble:

The idiom you used to have awk print (i.e.: grep <re> | awk '{print ...}') involves an extra "pipe" step. A simple awk '/<re>/{print ...}' does the same thing and is, generally, much more flexible.

More later. (I'm still coughing...)

If you were to use gawk instead of mixing your languages, you might find life simplier.

Here's simple a rewrite of the non-distro-specific part of your script to get you started, if you wish. (I don't have a Debian distro installed, so I don't have a /var/log/kern file with which to play.)

Note the the uptime on my Fedora system accepts arguments:
$ uptime -h

 uptime [options]

 -p, --pretty   show uptime in pretty format
 -h, --help     display this help and exit
 -s, --since    system up since
 -V, --version  output version information and exit

For more details see uptime(1).
#!/bin/gawk -f
# Get disk model/serial numbers, etc
  cmd = "ls -l /dev/disk/by-id"
  while (cmd | getline idinfo) {
    nf=split(idinfo, Info)
    if (nf != 11) continue
    device="/dev/" substr(Info[11],7)
    if (length(device) > mdev) mdev=length(device)
    if ((device ~ /[[:digit:]]$/) && (Info[9] ~ /-part/)) {continue}
    description = substr(Info[9],1+match(Info[9],/-/))
    if (length(description) > max) max=length(description)+2
  for (i=1;i<=ndev;++i) {
    printf("%-" mdev "s  ",SData[i])
    for (j in Data[SData[i]]) {printf("%-" max "s",Data[SData[i]][j])}

# Get the date of the last boot and the time the system has been up
  cmd="uptime -s"
  if (cmd | getline boot_time) {
    if (match(boot_time,/[[:space:]]+/)) {
      printf("\nLast boot: %s at %s.\n", substr(boot_time,1,RSTART-1), substr(boot_time,RSTART+RLENGTH))
      # Get the time the system has been running
    else {
      printf("/nUnexpected return (\"%s\") from \"%s\".\n", uptime, cmd)
  cmd="uptime -p"
  if (cmd | getline run_time) {
    if (match(run_time,/[[:space:]]+/)) {
      printf("Running for %s.\n", substr(run_time,RSTART+RLENGTH))
    else {
      printf("/nUnexpected return (\"%s\") from \"%s\".\n", run_time, cmd)
Which, on my Fedora system shows (after saving the script and making it executable):
$ ./affinityvision.gawk 
/dev/md126  name-HP-p6710f:127                        uuid-31ae217a:e7564465:9e527f40:40dcd2b8  
/dev/sda    ST31000528AS_6VPBQVS7                     0x5000c50032d81e7f                        
/dev/sdb    ST2000DL003-9VT166_5YD3C2FZ               0x5000c500385662bf                        
/dev/sdc    WDC_WD20EARX-00PASB0_WD-WMAZA8382941      0x50014ee25c328225                        
/dev/sdd    Generic-_SD_MMC_18E391066476-0:0          
/dev/sde    Generic-_Compact_Flash_18E391066476-0:1   
/dev/sdf    Generic-_SM_xD-Picture_18E391066476-0:2   
/dev/sdg    Generic-_MS_MS-Pro_18E391066476-0:3       
/dev/sr0    hp_DVD_A_DH16ABLH_3L8108904593            

Last boot: 2014-02-15 at 10:44:02.
Running for 2 hours, 23 minutes.

Last edited by PTrenholme; 02-15-2014 at 03:17 PM. Reason: I noticed tha uptime took some useful arguments...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running "mainline" Linux on Xen: FAILED to find root device bojanap Linux - Kernel 1 09-17-2010 11:42 PM
LVM has lost the plot - "Couldn't find device with uuid...." The Fold Slackware 0 10-21-2008 09:54 AM
FC6 Install Problem: "Unable to find any device of the type needed for instal" AeroGT3 Fedora 23 05-21-2008 10:40 PM
Can't find the "Linux Device Drivers" online book! gentoolman Linux - Hardware 4 01-16-2007 12:36 PM
"Cannot find root device" this is a bad error right? steventux Linux - General 1 02-23-2003 02:42 AM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 03:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration