jefferson1 Posted April 29, 2020 Report Posted April 29, 2020 need to create a batch file for two things 1. Server B lo log files untai on a particular folder, file limit 50MB. once the file size reaches 50MB another file will be created to write logs. Need a script to zip the 50mb file copy it to another server A and unzip it. 2. delete the files from Server A if they are two days old. Quote
bhaigan Posted April 29, 2020 Report Posted April 29, 2020 @KumarUncle is expert in this @Kootami Quote
Spartan Posted April 29, 2020 Report Posted April 29, 2020 20 minutes ago, jefferson1 said: ltt You can write a powershell script which monitors the folder, and define an action what u want to do when new file gets created.. This script monitors a certain folder and writes a logfile. You can replace the action and do whatever you want e.g call an external tool ### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "D:\source" $watcher.Filter = "*.*" $watcher.IncludeSubdirectories = $true $watcher.EnableRaisingEvents = $true ### DEFINE ACTIONS AFTER AN EVENT IS DETECTED $action = { $path = $Event.SourceEventArgs.FullPath $changeType = $Event.SourceEventArgs.ChangeType $logline = "$(Get-Date), $changeType, $path" Add-content "D:\log.txt" -value $logline } ### DECIDE WHICH EVENTS SHOULD BE WATCHED Register-ObjectEvent $watcher "Created" -Action $action Register-ObjectEvent $watcher "Changed" -Action $action Register-ObjectEvent $watcher "Deleted" -Action $action Register-ObjectEvent $watcher "Renamed" -Action $action while ($true) {sleep 5} How to use Create a new text file Copy & paste the above code Change the following settings to your own needs: folder to monitor: $watcher.Path = "D:\source" file filter to include only certain file types: $watcher.Filter = "*.*" include subdirectories yes/no: $watcher.IncludeSubdirectories = $true Save and rename it to StartMonitoring.ps1 Start monitoring by Right click » Execute with PowerShell To stop monitoring, it's enough to close your PowerShell window More Info: https://superuser.com/questions/226828/how-to-monitor-a-folder-and-trigger-a-command-line-action-when-a-file-is-created 2 Quote
jefferson1 Posted April 29, 2020 Author Report Posted April 29, 2020 38 minutes ago, Spartan said: You can write a powershell script which monitors the folder, and define an action what u want to do when new file gets created.. This script monitors a certain folder and writes a logfile. You can replace the action and do whatever you want e.g call an external tool ### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "D:\source" $watcher.Filter = "*.*" $watcher.IncludeSubdirectories = $true $watcher.EnableRaisingEvents = $true ### DEFINE ACTIONS AFTER AN EVENT IS DETECTED $action = { $path = $Event.SourceEventArgs.FullPath $changeType = $Event.SourceEventArgs.ChangeType $logline = "$(Get-Date), $changeType, $path" Add-content "D:\log.txt" -value $logline } ### DECIDE WHICH EVENTS SHOULD BE WATCHED Register-ObjectEvent $watcher "Created" -Action $action Register-ObjectEvent $watcher "Changed" -Action $action Register-ObjectEvent $watcher "Deleted" -Action $action Register-ObjectEvent $watcher "Renamed" -Action $action while ($true) {sleep 5} How to use Create a new text file Copy & paste the above code Change the following settings to your own needs: folder to monitor: $watcher.Path = "D:\source" file filter to include only certain file types: $watcher.Filter = "*.*" include subdirectories yes/no: $watcher.IncludeSubdirectories = $true Save and rename it to StartMonitoring.ps1 Start monitoring by Right click » Execute with PowerShell To stop monitoring, it's enough to close your PowerShell window More Info: https://superuser.com/questions/226828/how-to-monitor-a-folder-and-trigger-a-command-line-action-when-a-file-is-created thanks bro Quote
pawanmb6 Posted April 29, 2020 Report Posted April 29, 2020 2 minutes ago, jefferson1 said: thanks bro bro check pm Quote
Spartan Posted May 1, 2020 Report Posted May 1, 2020 28 minutes ago, jefferson1 said: ltt paina cheppina hint pani cheyale. Quote
jefferson1 Posted May 1, 2020 Author Report Posted May 1, 2020 11 minutes ago, Spartan said: paina cheppina hint pani cheyale. maku batch script kavali bro... not windows shell Quote
ShruteSastry Posted May 1, 2020 Report Posted May 1, 2020 You can trigger this ps1 file using task scheduler, which works like batch job. It is recommended to move away from .exe type of batch scripts bro. Quote
jefferson1 Posted May 1, 2020 Author Report Posted May 1, 2020 4 minutes ago, ShruteSastry said: You can trigger this ps1 file using task scheduler, which works like batch job. It is recommended to move away from .exe type of batch scripts bro. on windows meeda cheyali... you have any script to do that? Quote
Spartan Posted May 1, 2020 Report Posted May 1, 2020 5 minutes ago, jefferson1 said: on windows meeda cheyali... you have any script to do that? windows lo ne..task scheduler ki velli.. add this to run in loop every 1 min or so...it will run this ps file Quote
jefferson1 Posted May 1, 2020 Author Report Posted May 1, 2020 14 minutes ago, Spartan said: windows lo ne..task scheduler ki velli.. add this to run in loop every 1 min or so...it will run this ps file nuvvu paina cheppina script event detection ki undi, kani zip and copy log file over network kavali Quote
ShruteSastry Posted May 1, 2020 Report Posted May 1, 2020 look at robocopy commands bro, play with them a little. You can get it. Use the below for reference. https://superuser.com/questions/877976/windows-command-line-to-move-files-over-a-certain-size Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.