! script name: tsm.d/listscripts
! topic: list recent scripts run
! Version_270423.a

!A
!A NAME:
!A
!A      List Scripts
!A
!A DESCRIPTION:
!A
!A      List a history of scripts run recently, and allow choice
!A      for script execution.
!A
!B INSTRUCTIONS:
!B
!B      SELECT SCRIPT FROM LIST
!B
!C
!C      Set the script variable "Num_scripts" to define the length of the
!C      script list.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: list scripts")

DIM Answer$[256],Namelist$[8000],Script$[80]
INTEGER Snum


Num_scripts=15          !set this value to define size of list
                        !i.e. show me the last 15 scripts run

Stat=StartProcess("grep 'Script File' scriptlog | awk ' { print $4 } ' | grep \.d | tail -"&VAL$(Num_scripts)&" >/tmp/slist")

Namelist$=""
Num_lines=FileLineCount("/tmp/slist")
FOR J= Num_lines-1 TO 1 STEP -1
        Stat=GetFileLine("/tmp/slist",J,Script$)
        IF NOT POS(Script$,"listscripts") THEN Namelist$=Namelist$&Script$&","
NEXT J

Stat=SetInputFormat("a99","")
Stat=GeneralListBox("LAST "&VAL$(Snum)&" SCRIPTS","CHOOSE SCRIPTS",Namelist$)
Stat=GetValue("SELECT EXISTING SCRIPT",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerSelectBox

LOAD Answer$

Leave:!

LowerSelectBox
Stat=SetInputFormat("n4","")

IF (NOT LEN(Destination$)) THEN
         LOAD "typecontrol"
ELSE
         LOAD Destination$
END IF
END
