Ask Your Question
0

How to display a date sorted list of images with date field

asked 2015-07-10 09:50:03 -0600

updated 2015-09-16 09:59:19 -0600

I've written this batch file to list images by date, it runs slow and relies on the gnu unix utilities. I was wondering if there was a faster way to do this


@echo off
rem  batch file # ==========================================================
rem  Name...........: getimagebyage.bat
rem  Description ...: List images by age
rem  Parameters ....: 
rem     %1 -  filter
rem  Returns .......: 
rem  Author  .......:  Thomas Bodine
rem  Modified.......:
rem  Remarks .......:
rem ======================================================================
if not exist output md output
nova image-list > output/images.txt
set target=output/images.txt
if [%1] == [] goto :nofilter
  grep -i %1  output/images.txt > output/imageFiltered.txt
  set target=output/imageFiltered.txt
:nofilter
cut -c42-98 %target% > output/imageNames.txt
C:\Windows\System32\find.exe /v "-----" output/imageNames.txt > output/justNames.txt 2> NUL:
del /q output\imageage.txt
for /f "tokens=*" %%A in (output\justNames.txt) do call :getage %%A  
sort output/imageage.txt > output/sortedImageAge.txt
start "" C:\Windows\System32\notepad.exe output/sortedImageAge.txt
goto :EOF
:getage
  rem echo on
  if [%1]==[] goto :EOF
  if [%1]==[----------] goto :EOF
  if [%1]==[Name] goto :EOF
  set imageName=%*
  glance image-show "%imageName%" > output\imageinfo.txt
  perl -n -e "print $1,'  ',""%imageName%\r\n"" if (/updated.*(\s\d\d\S+)/)" output\imageinfo.txt
  perl -n -e "print $1,'  ',""%imageName%\r\n"" if (/updated.*(\s\d\d\S+)/)" output\imageinfo.txt >> output\imageage.txt
  @echo off
goto :EOF
:EOF



Thanks for your time and attention.
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2015-09-14 15:18:46 -0600

Works great, here's the output:

 2014-08-26T12:09:11  RHEL-6.5
 2014-09-06T14:27:40  cirros-0.3.2-x86_64
 2014-09-08T09:13:27  ICFPP_IMAGE
 2014-10-08T14:01:16  ICFPP_IMAGE_100GB_Oct2014
 2014-10-27T10:37:42  trusty-server-cloudimg-amd64-disk1.img1414403314246
 2014-11-14T18:00:51  windows-2012-r2-std_2014-11-14-v6
 2014-11-14T18:09:17  windows-2008-r2-std_2014-11-14-v6
edit flag offensive delete link more
0

answered 2015-09-15 08:26:29 -0600

updated 2015-09-15 08:33:38 -0600

You could write it entirely as a perl (*) script, that would cut a bit on shell processing, and be a bit better.

Another remark is your "cut -c42-98" may break easily on input changes. I'd use regex parsing for that...

(*) or python, ruby, etc... but I saw you already use perl, which is fine.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-07-10 09:50:03 -0600

Seen: 414 times

Last updated: Sep 16 '15