Re: Dunce awk question
On Sep 25, 2015, at 6:41 AM, William A. Mahaffey III wrote: I am trying to use awk & grep to fashion a command to print out HDD temps, along w/ some identifying info: I've been doing something similar, except with sed #!/bin/mksh -p mbmon -c 1 | sed -n '2{ h s/, .*$// p } ' atactl wd0d smart status | sed -n '/^194/{ h s/^194.*Temperature[ ]*/wd0d =/ p } #tempget Temp.= 31.0 wd0d = 28 The first grabs only line 2, and deletes everything after the first comma. The second grabs the line the begins with 194... If I wanted do that with awk. #atactl wd0d smart status| awk '/^194/{print ($8) } ' 33 or #atactl wd0d smart status| awk '/^194/{print ($7, "wd0d", $8) } ' Temperature wd0d 34 I can grab the model like this. #atactl wd0d identify | awk '/^Model:/{print ($2) }' ST380021A, Which leaves me with a pesky comma, or with sed. #atactl wd0d identify | sed -n '1{ h s/^Model:// s/, .*$// p }' ST380021A I am only *weakly* familiar w/ GNU awk, where the above works. awk's printf would expect to begin with format like C's printf. The standard idiom is to use '{print $8}', but then if you want to do more, you have to remember both the parens, and the commas, so now I always do '{print ($8)}' .
Re: Dunce awk question
On 09/26/15 13:41, Dan LaBell wrote: On Sep 25, 2015, at 6:41 AM, William A. Mahaffey III wrote: I am trying to use awk & grep to fashion a command to print out HDD temps, along w/ some identifying info: I've been doing something similar, except with sed #!/bin/mksh -p mbmon -c 1 | sed -n '2{ h s/, .*$// p } ' atactl wd0d smart status | sed -n '/^194/{ h s/^194.*Temperature[ ]*/wd0d =/ p } #tempget Temp.= 31.0 wd0d = 28 The first grabs only line 2, and deletes everything after the first comma. The second grabs the line the begins with 194... If I wanted do that with awk. #atactl wd0d smart status| awk '/^194/{print ($8) } ' 33 or #atactl wd0d smart status| awk '/^194/{print ($7, "wd0d", $8) } ' Temperature wd0d 34 I can grab the model like this. #atactl wd0d identify | awk '/^Model:/{print ($2) }' ST380021A, Which leaves me with a pesky comma, or with sed. #atactl wd0d identify | sed -n '1{ h s/^Model:// s/, .*$// p }' ST380021A I am only *weakly* familiar w/ GNU awk, where the above works. awk's printf would expect to begin with format like C's printf. The standard idiom is to use '{print $8}', but then if you want to do more, you have to remember both the parens, and the commas, so now I always do '{print ($8)}' . I wound up fancying everything up into a shell script: [wam@4256EE1, ~, 7:31:08am] 523 % cat `which hddtemp` #! /bin/csh -f # Using your version string above, the following works for me: # # % echo 'Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: # JR10046P1D5UXN' | awk '/Model/ { print $3 }' # HTS721010A9E630, # # Some rules I usually go by: # 1. Piping through grep and awk is almost always wrong - awk has some # fine regexps, you should just use them # 2. Different disks and virtual disks report using different formats. # For instance, for me on a VM: # # % sudo atactl wd0 identify # Model: VMware Virtual IDE Hard Drive, Rev: 0001, Serial #: # 0001 # # and the third field in that string is "Virtual" # # 3. Most uses of "just print this" in awk for me use the "print" verb. # "printf" needs a format string, same as in C. # echo 'Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN' | awk '/Model/{print $3}' echo "SMART supported, SMART enabled" foreach drive ($*) echo -n 'drive '$drive': '; sudo atactl $drive identify | awk '/Model/ {ORS = ", "; print $2, $3, "S/N:", $8}' - sudo atactl $drive smart status | awk '/Temp/ {print "Temp.", $8, "degC,", $9, $10, $11, "degC"}' - # echo -n 'drive '$drive': '; sudo atactl $drive identify | grep Model | awk '{ORS = ", "; print $2, $3, "S/N:", $8}' - # sudo atactl $drive smart status | grep Temp | awk '{print "Temp.", $8, "degC", $9, $10, $11, "degC"}' - end [wam@4256EE1, ~, 7:41:46pm] 524 % envstat ; hddtemp wd0 wd1 wd2 wd3 wd4 wd5 Current CritMax WarnMax WarnMin CritMin Unit [amdtemp0] cpu0 temperature:33.000 degC SMART supported, SMART enabled drive wd0: HGST HTS721010A9E630, S/N: JR10046P1D5UXN, Temp. 31 degC, Lifetime min/max 21/40 degC drive wd1: HGST HTS721010A9E630, S/N: JR10046P1D605N, Temp. 32 degC, Lifetime min/max 21/42 degC drive wd2: HGST HTS721010A9E630, S/N: JR10046P1D5TZN, Temp. 31 degC, Lifetime min/max 21/40 degC drive wd3: HGST HTS721010A9E630, S/N: JR10046P1EK9GN, Temp. 32 degC, Lifetime min/max 21/41 degC drive wd4: HGST HTS721010A9E630, S/N: JR10046P1EJ4UN, Temp. 30 degC, Lifetime min/max 20/38 degC drive wd5: HGST HTS721010A9E630, S/N: JR10046P1D5V2N, Temp. 31 degC, Lifetime min/max 21/39 degC [wam@4256EE1, ~, 7:43:24pm] 525 % *Wohooo* Thanks for all the pointers :-). -- William A. Mahaffey III -- "The M1 Garand is without doubt the finest implement of war ever devised by man." -- Gen. George S. Patton Jr.
Re: Dunce awk question
H All good observations, especially the multiple pipes, I'll look into that. Thanks :-) On 09/25/15 11:13, Alistair Crooks wrote: Using your version string above, the following works for me: % echo 'Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN' | awk '/Model/ { print $3 }' HTS721010A9E630, Some rules I usually go by: 1. Piping through grep and awk is almost always wrong - awk has some fine regexps, you should just use them 2. Different disks and virtual disks report using different formats. For instance, for me on a VM: % sudo atactl wd0 identify Model: VMware Virtual IDE Hard Drive, Rev: 0001, Serial #: 0001 and the third field in that string is "Virtual" 3. Most uses of "just print this" in awk for me use the "print" verb. "printf" needs a format string, same as in C. Regards, Al On 25 September 2015 at 08:34, William A. Mahaffey IIIwrote: I am trying to use awk & grep to fashion a command to print out HDD temps, along w/ some identifying info: [wam@4256EE1, ~, 10:41:29am] 418 % sudo atactl wd0 identify | grep Model Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN [wam@4256EE1, ~, 10:41:31am] 419 % sudo atactl wd0 identify | grep Model | awk '{printf $3 " "}' - [wam@4256EE1, ~, 10:41:32am] 420 % uname -a NetBSD 4256EE1.CFD.COM 6.1.5 NetBSD 6.1.5 (GENERIC) amd64 [wam@4256EE1, ~, 10:41:34am] 421 % I am only *weakly* familiar w/ GNU awk, where the above works. What am I missing here, I expected the above to print out the model # of the HDD. Please apply the clue-bat generously :-) -- William A. Mahaffey III -- "The M1 Garand is without doubt the finest implement of war ever devised by man." -- Gen. George S. Patton Jr. -- William A. Mahaffey III -- "The M1 Garand is without doubt the finest implement of war ever devised by man." -- Gen. George S. Patton Jr.
Re: Dunce awk question
Using your version string above, the following works for me: % echo 'Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN' | awk '/Model/ { print $3 }' HTS721010A9E630, Some rules I usually go by: 1. Piping through grep and awk is almost always wrong - awk has some fine regexps, you should just use them 2. Different disks and virtual disks report using different formats. For instance, for me on a VM: % sudo atactl wd0 identify Model: VMware Virtual IDE Hard Drive, Rev: 0001, Serial #: 0001 and the third field in that string is "Virtual" 3. Most uses of "just print this" in awk for me use the "print" verb. "printf" needs a format string, same as in C. Regards, Al On 25 September 2015 at 08:34, William A. Mahaffey IIIwrote: > > > I am trying to use awk & grep to fashion a command to print out HDD temps, > along w/ some identifying info: > > [wam@4256EE1, ~, 10:41:29am] 418 % sudo atactl wd0 identify | grep Model > Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN > [wam@4256EE1, ~, 10:41:31am] 419 % sudo atactl wd0 identify | grep Model | > awk '{printf $3 " "}' - > [wam@4256EE1, ~, 10:41:32am] 420 % uname -a > NetBSD 4256EE1.CFD.COM 6.1.5 NetBSD 6.1.5 (GENERIC) amd64 > [wam@4256EE1, ~, 10:41:34am] 421 % > > I am only *weakly* familiar w/ GNU awk, where the above works. What am I > missing here, I expected the above to print out the model # of the HDD. > Please apply the clue-bat generously :-) > > > -- > > William A. Mahaffey III > > -- > > "The M1 Garand is without doubt the finest implement of war > ever devised by man." >-- Gen. George S. Patton Jr. >
Re: Dunce awk question
On Fri, Sep 25, 2015 at 8:34 AM, William A. Mahaffey IIIwrote: > > > I am trying to use awk & grep to fashion a command to print out HDD temps, > along w/ some identifying info: > > [wam@4256EE1, ~, 10:41:29am] 418 % sudo atactl wd0 identify | grep Model > Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN > [wam@4256EE1, ~, 10:41:31am] 419 % sudo atactl wd0 identify | grep Model | > awk '{printf $3 " "}' - > [wam@4256EE1, ~, 10:41:32am] 420 % uname -a > NetBSD 4256EE1.CFD.COM 6.1.5 NetBSD 6.1.5 (GENERIC) amd64 > [wam@4256EE1, ~, 10:41:34am] 421 % > > I am only *weakly* familiar w/ GNU awk, where the above works. What am I > missing here, I expected the above to print out the model # of the HDD. > Please apply the clue-bat generously :-) print not printf Andy
Re: Dunce awk question
On 2015-09-25 11:41, William A. Mahaffey III wrote: I am trying to use awk & grep to fashion a command to print out HDD temps, along w/ some identifying info: [wam@4256EE1, ~, 10:41:29am] 418 % sudo atactl wd0 identify | grep Model Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN [wam@4256EE1, ~, 10:41:31am] 419 % sudo atactl wd0 identify | grep Model | awk '{printf $3 " "}' - [wam@4256EE1, ~, 10:41:32am] 420 % uname -a NetBSD 4256EE1.CFD.COM 6.1.5 NetBSD 6.1.5 (GENERIC) amd64 [wam@4256EE1, ~, 10:41:34am] 421 % I am only *weakly* familiar w/ GNU awk, where the above works. What am I missing here, I expected the above to print out the model # of the HDD. Please apply the clue-bat generously :-) You almost certainly don't need grep when awk is involved: echo 'Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN' | awk '/Model/{print $3}' seems to work for me... -- da...@chromiq.org
Re: Dunce awk question
On 09/25/15 11:18, David wrote: On 2015-09-25 11:41, William A. Mahaffey III wrote: I am trying to use awk & grep to fashion a command to print out HDD temps, along w/ some identifying info: [wam@4256EE1, ~, 10:41:29am] 418 % sudo atactl wd0 identify | grep Model Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN [wam@4256EE1, ~, 10:41:31am] 419 % sudo atactl wd0 identify | grep Model | awk '{printf $3 " "}' - [wam@4256EE1, ~, 10:41:32am] 420 % uname -a NetBSD 4256EE1.CFD.COM 6.1.5 NetBSD 6.1.5 (GENERIC) amd64 [wam@4256EE1, ~, 10:41:34am] 421 % I am only *weakly* familiar w/ GNU awk, where the above works. What am I missing here, I expected the above to print out the model # of the HDD. Please apply the clue-bat generously :-) You almost certainly don't need grep when awk is involved: echo 'Model: HGST HTS721010A9E630, Rev: JB0OA3J0, Serial #: JR10046P1D5UXN' | awk '/Model/{print $3}' seems to work for me... Yes, thanks :-) -- William A. Mahaffey III -- "The M1 Garand is without doubt the finest implement of war ever devised by man." -- Gen. George S. Patton Jr.