LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
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?

Notices


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

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354

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

<edit>
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:
Code:
$ uptime -h

Usage:
 uptime [options]

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).
Code:
#!/bin/gawk -f
# Get disk model/serial numbers, etc
#
BEGIN {
  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
    Data[device][1+length(Data[device])]=description
  }
  close(cmd)
  ndev=asorti(Data,SData)
  for (i=1;i<=ndev;++i) {
    printf("%-" mdev "s  ",SData[i])
    for (j in Data[SData[i]]) {printf("%-" max "s",Data[SData[i]][j])}
    printf("\n")
  }
}

# Get the date of the last boot and the time the system has been up
BEGIN {
  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)
    }
    close(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)
    }
    close(cmd)
  }
}
Which, on my Fedora system shows (after saving the script and making it executable):
Code:
$ ./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.
</edit>

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


Reply



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 kernel.org "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

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 06:47 PM.

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