rblog

Windows – Search for files using WQL

Needed a script that searches a the entire disk for Java dump files (core, snap, heap, javacore). In addition the files should not be older than X days to limit the search results. Since I have decided that all scripts I create that is related to server maintenance should be written in Powershell I just had to roll up my sleeves and head on to Google to be inspired. Below you can see the result.


param (
    [string]$logFile = $(throw "******************************`n" + 
			"Custom error:`nMissing required parameter -logFile." +
			"`nSpecify name without full path`n******************************`n`n")    
)
### Uncomment line below to enable debug
#$DebugPreference = "Continue"

# The script will search the d-drive by default
# If d does not exist it will search the c drive 
$drive = "d:"
If (!(Test-Path d:))
{
	$drive = "c:"
	If (!(Test-Path c:)) {
		throw "Did not find d or c-drive, script will cannot continue"
	}
}
$fullLogFile = Join-Path "$drive\temp\" "$logFile";
Start-Transcript $fullLogFile;


####
# Fixed variables
####
$notOlderThanDays = -7 # Change this to whatever amount of time you are looking for

$wmiQuery = "Select * from CIM_DataFile where Drive='$drive' AND FileName Like '{0}' AND Extension='{1}' AND CreationDate >= '{2}'"

# E.g core.20131030.052140.5448.0002.dmp
$core = "core%"
$coreExt = "dmp"

# E.g Snap.20131030.052140.5448.0001.trc
$snap = "Snap%"
$snapExt = "trc"

# E.g heapdump.20131030.052140.5448.0004.phd
$heap = "heapdump%"
$heapExt = "phd"

# javacore.20131030.052140.5448.0003.txt
$javacore = "javacore%"
$javacoreExt = "txt"

$date = Get-Date # Current time
$date = $date.AddDays($notOlderThanDays) 
$creationdate = Get-Date $date -Format G # This format is the format that the WMI commandlet likes

#####
# Start the fun
#####

# Corefiles
$runQuery = [String]::format($wmiQuery,$core,$coreExt,$creationdate)
Write-Debug "Start searching for core files"
Write-Debug $runQuery
Get-WmiObject -Query $runQuery | select Name

# Snapfiles
$runQuery = [String]::format($wmiQuery,$snap,$snapExt,$creationdate)
Write-Debug "Start searching for snap files"
Write-Debug $runQuery
Get-WmiObject -Query $runQuery

# Heapdumps
$runQuery = [String]::format($wmiQuery,$heap,$heapExt,$creationdate)
Write-Debug "Start searching for heap files"
Write-Debug $runQuery
Get-WmiObject -Query $runQuery

# Javacore
$runQuery = [String]::format($wmiQuery,$javacore,$javacoreExt,$creationdate)
Write-Debug "Start searching for javacore files"
Write-Debug $runQuery
Get-WmiObject -Query $runQuery

Stop-Transcript 

How can I return a 503 status in apache without invoking external scripts

This blog post How can I return a 503 status in apache without invoking external scripts basically explains it all, but I had to struggle a bit before I completely understood the needed arguments. So now I have the following lines at the end of the httpd.conf file (not for this domain but a server at work ๐Ÿ™‚ ).

Redirect 503 /test503
Redirect 404 /test404
Redirect 501 /test501
Redirect 504 /test504
Redirect 505 /test505
Redirect 502 /test502
Redirect 506 /test506

Note that you have to make sure that mod_alias is enabled

Blog upgraded

Now upgraded from 4.x to 5.0.5. Did not spend much time doing it, easy as always. Need to spend some more time to get the skin up and running as I would like, apart from that all was straightforward.

Performance tuning is hell!

Have previously struggled with the performance of site loading on my blog, always suspected that the problem was related to the database, but not really sure. But every time I have planned to find this out the problem has gone away, but lately the performance has been bad constantly. So off to Google, found the article about debugging B2Evolution http://manual.b2evolution.net/Debugging. First run, sloooooow, after that everything fast as lightning. Why did the problem go away? Beats me, suspect some MySQL-caching on the server, but must admit that I am guessing – honestly: I have no idea…but…debugging once helped somehow.

Facebook – Microsoft Outlook 2013 and corporate email address

As a backup if I for some reason would be locked out of my personal email account I usually configure various accounts with my corporate email as backup. So if all other fails, I still should be able to log on to the service, this time it was Facebook. No issue doing it I thought, since I only had configured my corporate address to be secondary backup. Other than that my Facebook wall is as restricted as it can be.

So then, on Friday my boss, which is not one of my friends on Facebook, told me that he had installed the latest version of the Outlook email client (2013). He also told me that my profile picture was taken from my FB-account, me as a sergeant in the army. That is one thing, since the profile picture is publicly available, but what was worse was that he also could see everything posted on my wall. Again, my wall is as limited as it can be, but not if you are accessing it using latest Outlook (guessing that you must be part of the same company, but hey…if you are working for WallMart the number of fellow employees are 2.1 million.

I easily removed this option by deleting my secondary email on FB…but, fu#ยค – how could I know? Anyhow, it just confirms the rules of social media (FB and others)

To protect yourself, there are certain things you should refrain from posting on your Facebook profile. This includes comments and gripes about your employer or co-workers. Think twice before going on a Facebook to rant about your religious and political convictions. Your convictions may offend a potential employer and result in you not getting a job. You should also be careful when posting pictures. There is always the chance that an employer may see your post. As a rule of thumb, if you wouldn’t want your boss to see it, don’t put it on Facebook.

Read more

Up and running again

After weeks of downtime my blog is finally up and running again. Single most important reason for the downtime was the hacker attack against the Linux servers hosted by my ISP, read more about it here iktnytt.no/problemer-….-servere-har-problemer/ (In Norwegian). Then, due to my summer vacation I have not been able to follow up needed steps to recover until today. Seems to be some more issues as well, performance is pretty bad, but I expect that to be caused by overall server load, expect it to improve over the next few days.

Using Notepad++ and regex to search and append text

Needed to search an access.log file from Apache where each line started with an ip-address. Due to a limitation in AWstats, see bityard.org/…/apache_awstats_x-forwarded-for I did have to update the current log file (and later update httpd.conf to get rid of difference in # of fields)

Anyhow, in order to get a workaround I needed to add the missing hyphen ‘-‘ for all requests that does not use the load balancer. Pretty simple, many blog posts on how to do it, e.g stackoverflow.com/…/using-regex-to-prefix-and-append-in-notepad. To append, use \1 (and \2 etc if needed). My regex expression was

^(?:[0-9]{1,3}\.){3}[0-9]{1,3}\s-

Confirmed by using http://gskinner.com/RegExr/.
Problem was that the ‘\1’ did not work…until I RTFM. I needed to add a parenthesis to create a collection so that Notepad++ (Or more correct the Regex-engine knew what I refer to when using ‘\n’).

(^(?:[0-9]{1,3}\.){3}[0-9]{1,3}\s-)

Hjem