1

I have a simple script that gives me some values from a file. I am using sed to get that vaules (syntax is given below). these commands were working fine till yesterday. but now I'm not getting any value when i run these command. I've not changed anything so I'm quite surprized that what is reason. can anyone please tell me how can i debug my problem? below is file text:

May  1 11:59:31 box2 kernel: usb 1-3: new high speed USB device using ehci_hcd and address 24
May  1 11:59:31 box2 kernel: usb 1-3: New USB device found, idVendor=0411, idProduct=0105
May  1 11:59:31 box2 kernel: usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=5
May  1 11:59:31 box2 kernel: usb 1-3: Product: USB-SATA Bridge
May  1 11:59:31 box2 kernel: usb 1-3: Manufacturer: BUFFALO
May  1 11:59:31 box2 kernel: usb 1-3: SerialNumber: 00001412AA38
May  1 11:59:31 box2 kernel: usb 1-3: configuration #1 chosen from 1 choice
May  1 11:59:31 box2 kernel: scsi27 : SCSI emulation for USB Mass Storage devices
May  1 11:59:38 box2 kernel: scsi 27:0:0:0: Direct-Access     BUFFALO  External HDD          PQ: 0 ANSI: 2 CCS
May  1 11:59:38 box2 kernel: sd 27:0:0:0: Attached scsi generic sg6 type 0
May  1 11:59:38 box2 kernel: sd 27:0:0:0: [sdf] 976773168 512-byte logical blocks: (500 GB/465 GiB)
May  1 11:59:38 box2 kernel: sd 27:0:0:0: [sdf] Write Protect is off
May  1 11:59:38 box2 kernel: sd 27:0:0:0: [sdf] Assuming drive cache: write through
May  1 11:59:38 box2 kernel: sd 27:0:0:0: [sdf] Assuming drive cache: write through
May  1 11:59:38 box2 kernel: sdf: sdf1
May  1 11:59:38 box2 kernel: sd 27:0:0:0: [sdf] Assuming drive cache: write through
May  1 11:59:38 box2 kernel: sd 27:0:0:0: [sdf] Attached SCSI disk

script is:

 SERIAL=$(sed -n '5s/A.*: //p' filename)
    SIZE=$(sed -n '10s/A.*: //p' filename)
    MOUNT=$(sed -n '14s/A.*: //p' filename)

3 Answers 3

12

I can only assume you were matching on the capital A in April and it no longer works because it's now May.

Maybe instead of 'A' you should be using '^'.

2
  • very nice catch May 1, 2012 at 20:16
  • @wfaulk: Hats off to you.
    – Kashif
    May 1, 2012 at 20:34
3

As well as what @wfaulk says, if the text provided is what you use then the numbers should be 6,11,15.

SERIAL=$(sed -n 's/.*SerialNumber: \(.*\)/\1/p' filename)
SIZE=$(sed -n 's/.*logical blocks: \(.*\)/\1/p' filename)

may be more reliable. I can't see a better way of getting the mount point though with the data given.

From the comments

MOUNT=$(sed -n 's/.* sd[a-z]: \(.*\)/\1/p' filenaem)
2
  • 1
    sed -n 's/.* sd[a-z]: \(.*\)/\1/p' for the mount point?
    – cjc
    May 1, 2012 at 20:42
  • @cjc: oooh yes - nice one !
    – user9517
    May 1, 2012 at 20:43
2

Things in log files can vanish due to log rotation. Last time I had to do this, I found the lshw utility very useful. For example, lshw -class disk -quiet will fulfil your needs. lshw is available by default on ubuntu and is available for centos/redhat as well (http://www.ducea.com/2006/06/03/install-lshw-on-rhel-fedora-centos/).

I know this is off-topic, but I hope it's useful to the OP.

1
  • I really like your idea. thanks for your input. may be i need it in future.
    – Kashif
    May 4, 2012 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.