Script help for omni. (459 Views)
Reply
Occasional Advisor
kampatel
Posts: 14
Registered: ‎07-21-2011
Message 1 of 11 (459 Views)
Accepted Solution

Script help for omni.

I am trying to write a script wherein I want to initialize two nearest date protected tape from current date for the fields as below:

 

root):/home/root#omnimm -list_pool Development

 

Status Medium Label          Location                            Full Protected

===============================================================================

Good [NFC777L2] Development  [HP:MSL6000 Series:    25]          Yes  08/06/11  - initialize via script

Good [NFC774L2] Development  [HP:MSL6000 Series:    22]          Yes  08/14/11

Good [NFC773L2] Development  [HP:MSL6000 Series:    24]          Yes  08/07/11 - initialize via script

Good [NFC784L2] Development  [HP:MSL6000 Series:    23]          Yes  08/13/11

Good [NFC787L2] Development  [HP:MSL6000 Series:    26]          No   08/14/11

 

I will initialize the script on friday so if the date is Aug 5 then the nearest date are 08/06 and 08/07 then these  should be initialized by command "omnimm -recycle"

 

I got the two fields by awk and sed as below:

 

NFC777L2  08/06/11

NFC774L2  08/14/11
NFC773L2  08/07/11
NFC784L2  08/13/11
NFC787L2  08/14/11

 

I am trying to take nearest two days with respect to current date and initializ  it via script but not sure how to put them in action. Any suggestion would be highly helpful.  

Thanking you in advance.

 

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 11 (453 Views)

Re: Script help for omni.

[ Edited ]

Hi:

 

How about something as simple as this

 

# awk '{print $2,$1}' file | sort -t"/"  -nk1,1 -nk2,2 | head -2


Regards!

 

...JRF...

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 3 of 11 (449 Views)

Re: Script help for omni.

Ideally you would use a language that supports date arithmetic like perl.  Then you can sort and pick the closest two.

Occasional Advisor
kampatel
Posts: 14
Registered: ‎07-21-2011
Message 4 of 11 (448 Views)

Re: Script help for omni.

(root):/var/scripts#sort -t"/" -nk1,1 -nk2,2 list.final Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File] [-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..

 

Not working

 

 

Occasional Advisor
kampatel
Posts: 14
Registered: ‎07-21-2011
Message 5 of 11 (446 Views)

Re: Script help for omni.

Not good in perl.

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 6 of 11 (441 Views)

Re: Script help for omni.

>sort -t"/" -nk1,1 -nk2,2 list.final

 

It probably doesn't like the -n before the -k: sort -t"/" -k1,1n -k2,2n list.final

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 7 of 11 (441 Views)

Re: Script help for omni.


kampatel wrote:

(root):/var/scripts#sort -t"/" -nk1,1 -nk2,2 list.final Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File] [-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..

 

Not working

 


Hi (again):

 

For HP-UX that should be:

 

# awk '{print $2,$1}' file | sort -t"/"  -kk1,1 -kn2,2 | head -2

 

...though reversing the 'k' and 'n' options works on Apple :-)

 

Regards!

 

...JRF...

Occasional Advisor
kampatel
Posts: 14
Registered: ‎07-21-2011
Message 8 of 11 (434 Views)

Re: Script help for omni.

root):/var/scripts#awk '{print $2,$1}' list.final | sort -t"/"  -kk1,1 -kn2,2 | head -2
Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File]
           [-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..

 

Sorry, Not working again.

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 9 of 11 (430 Views)

Re: Script help for omni.

[ Edited ]

>For HP-UX that should be: ... | sort -t"/"  -kk1,1 -kn2,2

 

sort(1) says that the type is after the field start or end: field_start [ type ] [,field_end [ type ] ]

Unless you want to use the global -n:  sort -t"/"  -n -k1,1 -k2,2 list.final

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 10 of 11 (428 Views)

Re: Script help for omni.


kampatel wrote:

root):/var/scripts#awk '{print $2,$1}' list.final | sort -t"/"  -kk1,1 -kn2,2 | head -2
Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File]
           [-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..

 

Sorry, Not working again.


Yes, and I can't type :-)

 

# awk '{print $2,$1}' file | sort -t"/"  -kn1,1 -kn2,2 | head -2

 

...not '-kk' as you copied from my mangled post.

 

Regards!

 

...JRF...

Occasional Advisor
kampatel
Posts: 14
Registered: ‎07-21-2011
Message 11 of 11 (407 Views)

Re: Script help for omni.

Thanks all getting the desired result.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.