Showing results for 
Search instead for 
Do you mean 

Script help for omni.

SOLVED
Go to Solution
Highlighted
Occasional Advisor

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.

 

1 ACCEPTED SOLUTION
Occasional Advisor

Re: Script help for omni.

Thanks all getting the desired result.

10 REPLIES
Acclaimed Contributor Acclaimed Contributor

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 Acclaimed Contributor

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

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

Re: Script help for omni.

Not good in perl.

Acclaimed Contributor Acclaimed Contributor

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 Acclaimed Contributor

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

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 Acclaimed Contributor

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 Acclaimed Contributor

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

Re: Script help for omni.

Thanks all getting the desired result.