0

Sorry for the semi-vague title, I wasn't exactly sure how to word it. I'm looking to generate a list, excluding devices without a matching major/minor number, and run

lkdev -l hdiskn -a -c DATAn

where the hdisk and the DATA device having corresponding major/minor numbers.

In /dev, I have -

root@ testbox /dev
#ls -l | grep -E "DATA|hdisk" | grep -v rhd
crw-r--r--    1 root     system       18,  3 Oct 03 10:50 DATA01
crw-r--r--    1 root     system       18,  2 Oct 03 10:50 DATA02
brw-------    1 root     system       18,  1 Apr 12 2013  hdisk0
brw-------    1 root     system       18,  0 Apr 12 2013  hdisk1
brw-------    1 root     system       18,  3 Jan 14 2014  hdisk2
brw-------    1 root     system       18,  2 Jan 14 2014  hdisk3
brw-------    1 root     system       18,  4 Jan 14 2014  hdisk4

So essentially, I'm trying to create something where hdisk0,1,4 are all excluded, and hdisk2-3 are locked with DATA01 and DATA02, respectively.

I originally was trying to use sort and/or uniq to isolate/remove fields, but haven't been able to generate the desired list to even begin looking at running the command on each.

(As a note, I have several servers with hundreds of these. If it were just these few, I'd find a "simpler" way.)

PassLin3
  • 3
  • 2
  • What do you mean by "locked" in "hdisk2-3 are locked with DATA01 and DATA02"? – asm Oct 03 '14 at 15:47
  • When you issue the command `lkdev -l hdisk2 -a -c DATA01` as an example, the command `lspv` will list the disk as being "locked" versus "active", etc. `root@ testbox /home/thisguy #lspv | grep locked hdisk2 none DATA01 locked` The purpose of this is to prevent the disk from having any characteristics modified. Because other servers have hundreds of these, using the DATA name that corresponds to the hdisk allows for much easier future reference. – PassLin3 Oct 03 '14 at 16:08
  • please edit your question to include the required output, given your sample input. Its also in the spirit of Stack Overflow to include your attempt at coding a solution (we're not a freebie consultancy;-), the output from that solution and your thoughts about why its not working. Good luck. – shellter Oct 03 '14 at 23:35
  • Apologies. I ended up getting this to work by generating a list of the hdisks with matching DATA devices and a list of all hdisks (in separate txt files), then using a while loop on the first list, using grep to print the lines with the major/minor numbers I wanted from the second list, and using awk to print the lkdev command with the variables in place. From there I piped to ksh to run the lkdev commands on each line. (I didn't know if it was worth posting the actual code or not.) Thanks! – PassLin3 Oct 06 '14 at 18:12

1 Answers1

0

(I can't test it right now, so please correct syntax errors if any)

You could play with sort en uniq like beneath

ls -l | grep -E "DATA|hdisk" | sed -e 's/.* \([0-9]*, *[0-9]*\).*/\1/' | sort | 
   uniq -c | grep -v "       1" | cut -c8- | while read majorminor; do
      ls -l | grep " ${majorminor}" | sed 's/.* //'
   done

However, you should start with selecting the right lines without counting:

for data in $(find /dev -type c -name "DATA*" | cut -d/ -f3); do
  majorminor="$(ls -l $data | sed -e 's/.* \([0-9]*, *[0-9]*\).*/\1/')"
  echo "$data <==> $(ls -l hdisk* | grep " ${majorminor}" | sed 's/.* //')"
done
Walter A
  • 19,067
  • 2
  • 23
  • 43