Solved

POWERSHELL

Posted on 2014-10-01
7
71 Views
Last Modified: 2015-02-04
Hello
3 files are uploaded in /tmp All days
name of files :
YYYYMMDD_TIME_file1.xml
YYYYMMDD_TIME_file2.xml
YYYYMMDD_TIME_file3.xml

i d like to monitor if the 3 files are well in /tmp All days.  and if no , email alert

How Can i do with powershell please?

Regards
Laurent
0
Comment
Question by:LaurentLyon
7 Comments
 
LVL 28

Expert Comment

by:becraig
ID: 40355673
i d like to monitor if the 3 files are well in /tmp All days.  and if no , email alert


I am not sure what you mean, do you mean you want to know if 3 files matching the current date exist in the folder ?

e.g today is
20141001  so you want to check whether
20141001  _TIME_file1.xml
20141001  _TIME_file2.xml
20141001  _TIME_file3.xml
exists, and send an email if they do not ?
0
 

Author Comment

by:LaurentLyon
ID: 40355687
Hello
Yes , and All days :)
i just want to know if they are well here , and if one file is not here then email alert
thanks
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 40355910
$basepath = "c:\test\"
$filter = get-date -Format yyyy-mm-dd
$filter2 = "*.xml"
$filter = $filter + $filter2
$items = Get-ChildItem -Path $basepath -Filter $filter2
$items.count
if ($items.count -lt 4) {
Write-Output ("send email")
}

Open in new window

0
 

Author Comment

by:LaurentLyon
ID: 40356685
Hello , thanks David ,

I d prefer that the script email an alert with the files missing ?


Regards
Laurent
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 40362613
$path = "c:\test"
$date = get-date -Format yyyy-mm-dd
[array]$files = @("$date*file1.xml","$date*file2.xml","$date*file3.xml")
foreach ($file in $files)
{
if (!(get-childitem -path $path -name $file))
{
send-mailmessage -from someone@some.com -to someone@some.como -subject "no file found" -body "file with name $file is not found in here" -smtpserver yoursmtp
}

}

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now