[Answered] K1000 Scripting - Can you verify a file was modified today?
In the Verify section of a script's tasks, one option is "Verify a file was modified since..." and you can select a file and a date, which has to be in YYYY-MM-DD format.
I was hoping to be able to verify that a file was modified today (or since yesterday, whichever works logically), but I can't find any documentation on date variables for such a thing. Does anyone know if they exist?
Alternatively, there is an option to edit the XML of a script. If you have "Verify a file was modified since..." selected, you'll find this line in there:
And that expectedValue will throw an error if you try to save it with anything but YYYY-MM-DD, saying
attribute 'expectedValue': 'today' i is not a valid value of the atomic type 'xs:date'.
Is there a way to get that to be the current date? I've read about , but I don't know how, if at all, to implement that. Thoughts on that?
0 Comments
[ + ] Show comments
Answers (2)
Answer Summary:
Please log in to answer
Posted by:
JasonEgg
7 years ago
I don't know if there's a way to do this from within the script itself or by modifying its XML. Two possible solutions: (1) start the script with a batch file that checks the modified date, set that step to "break" if it fails your test, or (2) create a custom inventory rule (CIR) which records the modified date of that file, then incorporate that CIR requirement into your target label. Let me know if you have questions about either of those.
Comments:
-
I'm currently getting around it with a CIR and a report, but since this is supposed to run on only one computer, the CIR is overhead for every other system we have.
The batch file is a good idea, though. I'll see if I can make that work, thanks! - ondrar 7 years ago
Posted by:
ondrar
7 years ago
Top Answer
I actually came up with a way to do this in PowerShell, and here it is, in case anyone would like to do the same.
In the Verify section of a task, select "Launch a Program" and fill it out as follows:
Directory: C:\Windows\System32\WindowsPowerShell\v1.0
File: powershell.exe
[X] Wait for completion
[ ] Visible
Parameters: -command & {if((get-date).day -eq ((get-item 'C:\path\file.txt').lastwritetime).day){exit 0}else{exit 1}}
This is looking at the day portion of today's date and the file's modified date, and seeing if they're the same. If so, it exits with status code 0; if not, it exits with status code 1. Exiting with 0 or 1 is what allows the verification to succeed or fail.
In my case, this file should be written every day, so only checking the day is fine (it could succeed once a month, if the file wasn't updated, but we'd have 29-30 days of errors in between). If you need a more specific date, you can probably use this as a starting point, and add onto it.
Hope this helps someone.