Sunday, April 1, 2012

Blackberry Enterprise Server -->Deleting log file on the basis of Age

Hi Readers,

I am just sharing a small script that you can use to schedule on your enviornment managements server & it will delete the logs from Bes/ BAS servers on the basis of age.

Just modify the script according to your enviornment. This script will map the droive from the BB server & will remove the unwanted logs. Below is the example for 90 days old logs. Also for my BB servers all the logs are placed in d drive (different from the binaries) ---thats important.

Also remove the Delete clause at first so that you will know what will be deleted. ones you are sure, append the delete clause.

##           Script to remove Log files                          ##
##           Author: Vikas Sukhija                     ##
##           Date: 03-30-2012                          ##
##  This scripts is used for deleting log files from Bes Servers ##
##  You can input the name of Bes server & number of days &      ##
##  logdrive path                                                ##
#Function remove logs created which will map the BES server drive & then dlete operation will be executed #

Function RemoveLogs ($BES, $path) {

$days = (get-date).adddays(-90)

# format date

$date = get-date -format d
# replace \ by -

$date = $date.ToString().Replace("/", "-")


$net = $(New-Object -ComObject WScript.Network)
$net.MapNetworkDrive("Y:", "\\$BES\d$")

$a= Get-ChildItem  $path | Where{$_.LastWriteTime -lt $days }

write-host $a

#write to Log file what files will be deleted
$output =  "C:\Scripts" + "\" + "logs" + "\" + "$BES" + "_" + "$date" + "_log.txt"

Add-content $output "$a log files have been deleted"

$a | Foreach-Object { del $_.FullName -recurse}

$net.RemoveNetworkDrive("Y:")
}

# define the path for logs

$path = "Y:\Program Files (x86)\Research In Motion\BlackBerry Enterprise Server"

# Call function removelogs for Bes servers

RemoveLogs EXBESP01 $path
RemoveLogs EXBESP02 $path
RemoveLogs EXBESP03 $path
RemoveLogs EXBASP01 $path
####################################################################################################

No comments:

Post a Comment