Hi Team,
We are looking to monitor the contents of a file which arrives once a day.
The file name will have the date in between "yyyymmdd.hhmm".
I have been looking for a batch file to help generate this patter so that we can add it to our existing check_logfiles plugin but haven't been successful.
Can someone please help with this?
File monitoring
Re: File monitoring
This might actually be easier with bash than with batch...
This is because the date command native to Unix derived systems have a built in formatting function, and that of Windows does not.
If you wanted to write the equivalent of that script for Windows, you would probably have to set each part of that date as a variable, and then reconstitute it as a new one to get it in that exact format.
Code: Select all
#!/bin/bash
file_name=$(date +%Y%m%d.%H%M)
if [ -f $file_name ]; then
echo "$file_name exists!"
else
echo "$file_name does not exist..."
fiIf you wanted to write the equivalent of that script for Windows, you would probably have to set each part of that date as a variable, and then reconstitute it as a new one to get it in that exact format.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
RebeccaIlene
- Posts: 164
- Joined: Tue Apr 02, 2019 8:38 pm
Re: File monitoring
Yes, I am looking to monitor this on Windows. Is there a powershell script that can help?
Re: File monitoring
Writing custom scripts is out of scope of Nagios support. Having said that, you could probably use something like this:
This is just to get you started. Adjust the path, and the value to your liking. You could use parameters instead of hard-coded values, etc. Again, this is out of scope of support.
For more information on adding new items via PS, review Microsoft documentation here:
https://docs.microsoft.com/en-us/powers ... wershell-7
Code: Select all
$myfile = get-date -format "yyyymmdd.hhmm"
New-Item -Path "c:\TEMP" -Name "$myfile" -ItemType "file" -Value "This is a test."For more information on adding new items via PS, review Microsoft documentation here:
https://docs.microsoft.com/en-us/powers ... wershell-7
Be sure to check out our Knowledgebase for helpful articles and solutions!