PDA

View Full Version : IT Question - checking if a file has been modified using a script...



JackaL
11-06-2004, 12:03
Does anyone know how (using vbscript, a batch file, or a sql query) I can provide a simple yes/no result (and run a command line program if no) as to whether a file has been modified within the past x minutes???

I need to check a file is being updated, and alert if it's not!

Cheers :)

docwra
11-06-2004, 12:17
I take it this is winders and not Unix?? Id use grep in unix, and Id buy a new server if it was windows ;)

SFC
11-06-2004, 12:21
Can vary with the platform but an easy way is to use cron or similar to periodically dump a detailed directory listing to a text file via a batch file/shell script and then diff the latest output file created against the last version either using an OS tool or bit of shareware. :nod:

SFC
11-06-2004, 12:21
I take it this is winders and not Unix?? Id use grep in unix, and Id buy a new server if it was windows ;)

and throw out 90% of your functionality ;)

Abaddon
11-06-2004, 12:25
use FC?

Dave_S
11-06-2004, 12:51
This VBScript should work :)



Dim jobbie, wotsit, doofer, spong

Set jobbie = CreateObject("Scripting.FileSystemObject")
Set wotsit = jobbie.GetFile("c:\file.txt")

doofer = wotsit.DateLastModified
' Gets the difference in seconds between when the file was modified and the current time
spong = DateDiff("s",doofer,Now())

If spong <= "300" Then
WScript.Echo("File has been modified in the last 5 minutes")
Else
WScript.Echo("Nope")
End If


Obviously replace "file.txt" with the file you want to check and the variable names to something more sensible ;) and what you want to do when the condition is met :)

HTH

Dave

docwra
11-06-2004, 12:54
and throw out 90% of your functionality ;)

Hell yeah!! Not to mention alienating 95% of your users :thumbs:

ScoobyDoo
11-06-2004, 13:06
Add unix commands to your win box :thumbs:

http://unxutils.sourceforge.net/

bc-1.05
bison-1.28
bzip2-1.0.2
diffutils-2.7
fileutils-3.16
findutils-4.1
flex-2.5.4
gawk-3.1.0
grep-2.4.2
gsar110
gzip-1.2.4
indent-2.2.9
jwhois-2.4.1
less-340
m4-1.4
make-3.78.1
patch-2.5
recode-3.6
rman-3.0.7
sed-3.02
shellutils-1.9.4
tar-1.12
textutils-2.1
unrar-3.00
wget-1.8.2
which-2.4

SFC
11-06-2004, 14:18
Hell yeah!! Not to mention alienating 95% of your users :thumbs:



:thumbs:

That's it, no use pi$$in against the wind. :no:

Our place had a Linux evangelist running IT until an independent review said "MS everything except basic web services" at which point he left and every user went "hoorah!"

The twat's left me with sys docs that say things like "we run sendmail, it never goes wrong because it's open source" but doesn't tell you which server it runs on, where its init and shutdown scripts are or anything else about the config. Total f*cking nightmare, I started in March with no working backups, no decent AV or AS, no proper policies, etc. etc. :annoyed:

Still, it's good to be busy. :)

RohanC
11-06-2004, 15:02
The twat's left me with sys docs that say things like "we run sendmail, it never goes wrong because it's open source"

Should have told him that Windows never fails cause it's expensive :nod:

What a tw@t though :wack:

JackaL
11-06-2004, 15:06
This VBScript should work :)

Obviously replace "file.txt" with the file you want to check and the variable names to something more sensible ;) and what you want to do when the condition is met :)

HTH

Dave


Cheers Dave :)

However, with a spong of between 3ish and 56ish it often gives a 'Nope' :confused:

ScoobyDoo
11-06-2004, 15:21
Ask yourself why they dont write norton anti-virus for freeBSD?

Im not knocking windows as we use Server 2k, MS exchange and ISA, but I also run freeBSD for mail routing to each mail server, AIX for core business application and SCO Openserver. And our intranet runs on Linux/Apache/MySQL (obvious choice!)

I can tell you which causes the most grief and day to day administration and thats Windows :smash:

hope this isnt off topic, but it seems thats the direction the thread was heading :D

JackaL
11-06-2004, 15:25
Ere! You lot with the box cutters and shoe bombs, GET ORF MY THREAD!!! You're not flying this one into the virtual equivalent of the twin towers :mad:

Besides, Windows is better, as it keeps me in a job! :p :nod:

JackaL
11-06-2004, 15:31
You've all got lots of free time...

Go test the spong test script :nod: :) It's totally random! ;)

siliconslave
11-06-2004, 16:00
This VBScript should work :)



Obviously replace "file.txt" with the file you want to check and the variable names to something more sensible ;) and what you want to do when the condition is met :)

HTH

Dave

quality bit of variable nameing there dave :D almost better than my usual var1, var2, var1-5 nameing methods ;)

SFC
11-06-2004, 16:11
Ask yourself why they dont write norton anti-virus for freeBSD?

Im not knocking windows as we use Server 2k, MS exchange and ISA, but I also run freeBSD for mail routing to each mail server, for core business application and SCO Openserver. And our intranet runs on Linux/Apache/MySQL (obvious choice!)

I can tell you which causes the most grief and day to day administration and thats Windows :smash:

hope this isnt off topic, but it seems thats the direction the thread was heading :D



Here we go :)

Linux servers are suffering more attacks than Windows ones at the mo, admittedly there are probably more of them as web servers and clients are a different matter altogether (but how many people are brave enough to try and run StarOffice/OpenOffice in a commercial environment?). Norton don't write an anti-virus for BSD cos the market's not big enough. If there were more Linux clients there'd be more Linux client-side viruses.

I've got nothing against Linux, in the right place, and agree that it's great running Apache for intranets, etc. However, when it comes to configuring the kind of integrated calendaring/scheduling/messaging/task management that you get out of the box with Exchange/Outlook you're on to a definite loser. Windows networks are much easier to manage centrally because all the management tools you need are there from day 1, no need to buy Unicentre/Tivoli/OpenView anymore but you do have to get the architecture nailed at the start. They are also cheaper on TCO/TLC.

At the end of the day I'm driven by users'/businesses' needs not technology and have no axes to grind on my own behalf. :thumbs:

JackaL
11-06-2004, 16:26
So... has anyone figured out why the script thinks that 641 seconds is less than 300???

Cheers :)

Dave_S
11-06-2004, 16:41
Jackal: That doesn't make any sense mate :confused:

Theres no way if spong is less than or equal to 300 that it could give nope?

EDIT: Try changing it to just < 300 instead of <= 300

Dave

JackaL
11-06-2004, 16:50
Jackal: That doesn't make any sense mate :confused:

Theres no way if spong is less than or equal to 300 that it could give nope?

EDIT: Try changing it to just < 300 instead of <= 300

Dave


Odd, I know...

I modify 'file.txt'
I save the file
I wait 20 secs
I run the script - it works
I run it a few more times quickly... After about go 6, it returns a 'nope', and 31 seconds (I added a line to echo the time, to see what it was up to). It keeps doing that then :confused:

Now looks like this, to make more sense to me... ;)

Dim v_Object, v_File, v_FileModDate, v_Diff

Set v_Object = CreateObject("Scripting.FileSystemObject")
Set v_File = v_Object.GetFile("c:\file.txt")

v_FileModDate = v_File.DateLastModified
' Gets the difference in seconds between when the file was modified and the current time
v_Diff = DateDiff("s",v_FileModDate,Now())


If v_Diff < "300" Then
WScript.Echo("File has been modified in the last 5 minutes")
WScript.Echo(v_Diff)
Else
WScript.Echo("Not modified recently")
WScript.Echo(v_Diff)
End If

Martin T
11-06-2004, 21:15
I would never let any of that open source sh1t run a network ;)
Great for firewalls though :D