Page 1 of 1
File monitoring
Posted: Mon Jun 15, 2020 9:35 pm
by RebeccaIlene
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?
Re: File monitoring
Posted: Tue Jun 16, 2020 3:20 pm
by jbrunkow
This might actually be easier with
bash than with
batch...
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..."
fi
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.
Re: File monitoring
Posted: Sun Jul 12, 2020 8:30 pm
by RebeccaIlene
Yes, I am looking to monitor this on Windows. Is there a powershell script that can help?
Re: File monitoring
Posted: Mon Jul 13, 2020 2:10 pm
by lmiltchev
Writing custom scripts is out of scope of Nagios support. Having said that, you could probably use something like this:
Code: Select all
$myfile = get-date -format "yyyymmdd.hhmm"
New-Item -Path "c:\TEMP" -Name "$myfile" -ItemType "file" -Value "This is a test."
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