Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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)
share|improve this question

3 Answers 3

up vote 12 down vote accepted

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 '^'.

share|improve this answer
    
very nice catch –  Lucas Kauffman May 1 '12 at 20:16
    
@wfaulk: Hats off to you. –  Kashif May 1 '12 at 20:34

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)
share|improve this answer
1  
sed -n 's/.* sd[a-z]: \(.*\)/\1/p' for the mount point? –  cjc May 1 '12 at 20:42
    
@cjc: oooh yes - nice one ! –  Iain May 1 '12 at 20:43

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.

share|improve this answer
    
I really like your idea. thanks for your input. may be i need it in future. –  Kashif May 4 '12 at 10:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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