Page 1 of 1 1
Topic Options
#17396 - 2002-02-12 11:44 PM Looking for script capability answers
Anonymous
Unregistered


Is it possible to have Kixtart check folders and subdirectories for files older than a specified amount of days and then delete them if they have "expired"?
Also can it be made to create a log file of all files accessed by a user such as mpegs, avi's, jpegs etc. so that Admins can pull up this log file? darnold@walkthru.org

Top
#17397 - 2002-02-13 12:17 AM Re: Looking for script capability answers
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
yes

As with any programming/scripting language, it can do almost anything that you are clever enough to have it do

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#17398 - 2002-02-13 12:28 AM Re: Looking for script capability answers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... Jason, first of all welcome to the board. Your first requirement is a cinch... lots of examples already on the board. A quich search should reveal.

Your second requirement... well, peronally I thing you're asking a lot. It seems every time I say it can't be done, Radimus proves me wrong. I curious to see what he comes up with on this one!

The gauntlet is down!

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#17399 - 2002-02-13 01:02 AM Re: Looking for script capability answers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
You can turn on File and Object Access as well as Process Tracking under auditing (at a price to the server responsiveness) and then cull the Event Viewer for that information. It would probably be easier to also employ 3rd party tools for retrieving the Event Viewer information. There are also stand alone software packages available that say they can do what your asking Jason. If worked on, it should be possible to do with KiXtart Les.
Top
#17400 - 2002-02-13 03:43 AM Re: Looking for script capability answers
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

An example of the logfile output by running for the following
directories: c:\winnt\help + c:\windows\help

code:

2001/04/05 04:40:15 delete 'c:\winnt\help\31users.FTS' (2001/03/03 05:24:09 size=76800 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\31users.hlp' (1996/10/14 03:38:00 size=58591 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.FTS' (2001/03/03 05:24:08 size=94720 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.hlp' (1996/10/14 02:38:00 size=32359 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.chm' (2001/01/14 13:47:18 size=21705 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.cnt' (2001/01/14 14:35:02 size=121 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.hlp' (2001/01/14 14:35:02 size=16804 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.cnt' (1996/10/14 03:38:00 size=502 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.hlp' (1996/10/14 03:38:00 size=12643 older 3 days)
.....
2001/04/05 04:40:15 delete 'c:\winnt\help\wangshl.cnt' (1996/10/14 02:38:00 size=102 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wangshl.hlp' (1996/10/14 02:38:00 size=8509 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.cnt' (1996/10/14 02:38:00 size=1888 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.hlp' (1996/10/14 02:38:00 size=26793 older 3 days)

An example of the screen output:

code:

check directory 'c:\windows\help'
check directory 'c:\winnt\help'

Informative DELETION: process completed. 112 files deleted + 2 files skipped.

directories checked:
'c:\windows\help'
'c:\winnt\help'
debug output: 'c:\temp\deletion_debug.txt'


The debug output looks:

code:

days 3
current date 2001/04/05
compare date 2001/04/02

check directory 'c:\windows\help'
check directory 'c:\winnt\help'
2001/04/05 04:40:15 delete 'c:\winnt\help\31users.FTS' (2001/03/03 05:24:09 size=76800 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\31users.hlp' (1996/10/14 03:38:00 size=58591 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.FTS' (2001/03/03 05:24:08 size=94720 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\access.hlp' (1996/10/14 02:38:00 size=32359 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\accessib.chm' (2001/01/14 13:47:18 size=21705 older 3 days)
-skip- 'c:\winnt\help\accessib.cnt'
-skip- 'c:\winnt\help\accessib.hlp'
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.cnt' (1996/10/14 03:38:00 size=502 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\acc_dis.hlp' (1996/10/14 03:38:00 size=12643 older 3 days)
.....
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocx.cnt' (1996/10/14 02:38:00 size=100 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocx.hlp' (1996/10/14 02:38:00 size=19229 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocxd.cnt' (1996/10/14 02:38:00 size=4415 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangocxd.hlp' (1996/10/14 02:38:00 size=291485 older 3 days)
2001/04/05 04:40:15 delete 'c:\winnt\help\wangshl.cnt' (1996/10/14 02:38:00 size=102 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wangshl.hlp' (1996/10/14 02:38:00 size=8509 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.cnt' (1996/10/14 02:38:00 size=1888 older 3 days)
2001/04/05 04:40:16 delete 'c:\winnt\help\wordpad.hlp' (1996/10/14 02:38:00 size=26793 older 3 days)


Our code is:

code:

;
; NT/95 delete files older then specified number of days - Kixtart 3.62, 3.63, 4.00
;
; (c) drillsergeant, mca - 2001
;
; vs 1.01 - program
;
; 1.00 (20010115) original version
; 1.01 (20010401)
;
CLS
BREAK on
FLUSHKB
MD "c:\temp"

IF (Len(@wksta) <> 0)
$wksta=@wksta
ELSE
$wksta="unknown"
ENDIF

; ---------------------------------------------------------------------------
; - site defined settings -
; ---------------------------------------------------------------------------

$debug_mode="yes" ; - yes/no -
$debug_file="c:\temp\deletion_debug.txt" ; - c:\temp\deletion_debug.txt = file
; - CON = means output to user screen

$days = 7 ; - delete files older than specified number of days -
$log_file="c:\temp\deletion_"+$wksta+".log" ; - append to this file -

$max_directories=2
DIM $remove_dir[$max_directories+1]
$remove_dir[1] = "c:\test1"
$remove_dir[2] = "c:\test2"

; ---------------------------------------------------------------------------
; - main program by DrillSergeant / MCA -
; ---------------------------------------------------------------------------

$temp_file="c:\temp\deletion.tmp"
$log_file=LCASE($log_file)
;
IF ($debug_mode = "yes")
DEL $debug_file
IF ReDirectOutput($debug_file)
ENDIF
ENDIF

; ---------------------------------------------------------------------------
; - Here you control whether files in subdirectories should be
; - or excluded, with the switch "/s".
; - The "/b" switch stands for "base notation", (which excludes
; - everything but the filename), don't change this one!
; ---------------------------------------------------------------------------

GOSUB "calculate_date"
?
IF Open(2,"$log_file",5)
ENDIF
;
$count_skipped=0
$count_delete=0
;
$i = 1
WHILE ($i <= $max_directories)
IF Close(1)
ENDIF
DEL $temp_file
? "check directory '"+$remove_dir[$i]+"'"
$command = '%comspec% /c dir "'+$remove_dir[$i]+'" /s /b >'+$temp_file
SHELL $command
IF (Open(1,$temp_file,2) = 0)
$line = ReadLine(1)
WHILE @error = 0
GOSUB "check_file"
$line = ReadLine(1)
LOOP
ENDIF
$i = $i + 1
LOOP
IF Close(1)
ENDIF
IF Close(2)
ENDIF
IF (Exist($temp_file) = 1)
DEL $temp_file
ENDIF
IF ReDirectOutput("CON")
ENDIF
? "Informative DELETION: process completed. "+
$count_delete+" files deleted + "+
$count_skipped+" files skipped."
?
? "directories checked: "
$i=1
WHILE ($i <= $max_directories)
? " '"+$remove_dir[$i]+"'"
$i=$i+1
LOOP
IF ($debug_mode = "yes")
? "debug output: '"+$debug_file+"'"
ENDIF
EXIT

; ------------------------------------------------------------------------
; - calculate the date (minus $days) by DrillSergeant - -
; ------------------------------------------------------------------------

:calculate_date
$cury = @year
$curm = @monthno
$curd = @mdayno
IF $curm < 3
$curm = $curm + 12
$cury = $cury - 1
ENDIF
$curint = $curd + ( 153 * $curm - 457 ) / 5 + 365 * $cury + $cury / 4 - $cury / 100 + $cury / 400 - 306
$myz = $curint - $days + 306
$myh = 100 * $myz - 25
$mya = $myh / 3652425
$myb = $mya - $mya / 4
$rd_year = (100 * $myb + $myh) / 36525
$myc = $myb + $myz - 365 * $rd_year - $rd_year / 4
$rd_month = (5 * $myc + 456) / 153
$rd_day = $myc - (153 * $rd_month - 457) / 5
IF $rd_month > 12
$rd_year = $rd_year + 1
$rd_month = $rd_month - 12
ENDIF
IF Len("$Rd_Month") = 1
$rd_month = "0" + "$Rd_Month"
ENDIF
IF Len("$Rd_Day") = 1
$rd_day = "0" + "$Rd_Day"
ENDIF
$compare_date = "$Rd_Year/$Rd_Month/$Rd_Day"
;
IF ($debug_mode = "yes")
? "days "+$days
? "current date "+@date
? "compare date "+$compare_date
ENDIF
RETURN

; ------------------------------------------------------------------------
; - check file for yes/no for deletion by DrillSergeant / MCA -
; ------------------------------------------------------------------------

:check_file
$time = GetFileTime($line)
IF ($time > "")
IF (Substr($time,1,10) < $compare_date)
$log_info=@date+" "+@time+" delete '"+$line+"'"+
" ("+GetFileTime($line)+
" size="+GetFileSize($line)+
" older "+$days+" days)"
IF WriteLine(2,$log_info+Chr(13)+Chr(10))
ENDIF
IF ($debug_mode = "yes")
? $log_info
ELSE
DEL $line ; <--------------------- delete files ------
ENDIF
$count_delete=$count_delete+1
ELSE
$log_info=" -skip- '"+$line+"'"
IF ($debug_mode = "yes")
? $log_info
ENDIF
$count_skipped=$count_skipped+1
ENDIF
ENDIF
RETURN


This please of code you can modify (site defined settings):

code:

$debug_mode="yes" ; - yes/no -
$debug_file="c:\temp\deletion_debug.txt" ; - c:\temp\deletion_debug.txt = file
; - CON = means output to user screen

$days = 7 ; - delete files older than specified number of days -
$log_file="c:\temp\deletion_"+$wksta+".log" ; - append to this file -

$max_directories=2
DIM $remove_dir[$max_directories+1]
$remove_dir[1] = "c:\test1"
$remove_dir[2] = "c:\test2"



The script may give you an idea.
Greetings.


btw: change $debug_mode="yes" to "no" for really file
deletion.

(our reaction 2100 to the board)

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#17401 - 2002-02-13 03:08 PM Re: Looking for script capability answers
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
hmmm... a challenge

first off a simple dir /s *.mpg >c:\mpg.log

if you wanted to know what they are watching/playing you could ENUMVALUE HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Player\RecentFileList
and or other players they may have installed

if you wanted to delete files older than a specified date / number of days, welll that is a bit more involved. You will need the datemath UDF fron the udf forum, and then do a dir on the specified directory, datemath it, the delete it if older than X number of days.

Is this sufficient, or do you want real code?

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#17402 - 2002-02-14 02:55 AM Re: Looking for script capability answers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Hey Rad,

I think MCA already gave him the code for the delete. As for the log of accessed files, yes your right in that many apps store the names and locations of recently accessed files. You could exploit that, but to get real logging of files accessed I think you would need to enable ALL AUDITING on NT under UserManager and/or use a 3rd party application.

KiX could certainly read through the Event Log and give back info... but not a very clean solution in my opinion.

Is this what your looking for Jason, or does any have any other suggestions?

Top
#17403 - 2002-02-14 06:05 AM Re: Looking for script capability answers
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ok try this one...

It is a bit rough, being still 'under construction' but it works... just needs to be tightened up and automate the deployment of it...

make a bat file someplace inconspicous... Winnt is good enough. Place this command into it:

%1 & echo %1 >>c:\player.log

save it

go into folder options\File types\file associations and find MP3 or Jpeg or whatever. Edit it's default action and replace it with

"c:\winnt\batch_file" "%1"

when you click on one of the files it ececutes the bat file and logs it name to the c: drive

[ 14 February 2002: Message edited by: Radimus ]

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#17404 - 2002-02-17 03:07 AM Re: Looking for script capability answers
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Still questions?
greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#17405 - 2002-02-18 07:39 PM Re: Looking for script capability answers
Anonymous
Unregistered


Yes,

The script that MCA posted and then e-mailed me is giving me "parse error 9" and not really checking the directories.

Any ideas?

-Jason Hand

Top
#17406 - 2002-02-19 12:37 AM Re: Looking for script capability answers
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Jason,

How are you calling our script?
Is it included in another script?
Which kixtart version running?
What changes did you make to our version?
Can you put the contents of file c:\temp\deletion_debug.txt on the board?
We send you another version which was extended with debugging code.

greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.065 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org