Categories
About

Scripts And HOWTOs

I work as an system administrator for a large educational institution in the Netherlands. I really enjoy automating tasks and over the course of time I’ve created several scripts to support this. When I think scripts can be reused I’ll publish them to this site. → Continue reading

Categories
PowerShell Scripting

PowerShell Cleanup Script

Cleanup logfiles when file change date is older than 30 days…

<#
    Description    : Cleanup logfiles when file change date is older than 30 days...
    Keywords       : Files, Change, Cleanup

    Majorversion   : 1

    Author         : Tim van Kooten Niekerk
    Date           : 2011-11-10
#>

<#      CHANGELOG:
        2013-12-12 => Add Headers (Tim van Kooten Niekerk)

#>


# Global config settings...
[string]$sDirName = "D:\LogFiles\W3SVC705438624"
[string]$sFileNameMask = "*.log"
[string]$sGCIMask = $sDirName + "\" + $sFileNameMask
[string]$sEventLogMessage = "### Logfile cleanup script started ###`r`n"


# Start Main script...
if (Test-Path $sDirName) {
get-childitem $sGCIMask | 
	% { 
		if ($_.LastWriteTime -lt (Get-date).AddDays(-30)) {
		remove-item $_.fullname
		$sEventLogMessage = $sEventLogMessage + "File " + $_.fullname + " (" + $dFileModTime.DateTime + ") removed...`r`n"
		}
	}
}


# Cleanup...
[string]$sEventLogMessage = $sEventLogMessage + "### Logfile cleanup script finished ###"
write-eventLog -LogName "Windows PowerShell" -Source "PowerShell" -EventID 30001 -Message $sEventLogMessage -EntryType Information

Categories
PowerShell Scripting

PowerShell Admin Functions (Module)

Some usefull (and less usefull) admin functions…

function fnGetFQDN() {
  param (
	  [switch]$swIsEmail = $false
  )
  $oNETIP = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
  if ($swIsEmail -eq $true) {
    [string]$Return1 = "noreply@" + $oNETIP.HostName + "." + $oNETIP.DomainName
  } else {
    [string]$Return1 = $oNETIP.HostName + "." + $oNETIP.DomainName
  }  
  return $Return1
}
Categories
MySQL Server

MySQL Convert UTC Timestamp to Specific Timezone

MySQL example to convert UTC timestamp to specific timezone.

SELECT 
  SensorName, 
  MAX(CONVERT_TZ(LastUpdated, 'UTC', 'Europe/Amsterdam')) AS LastUpdated
FROM Sensors 
WHERE (TIME_TO_SEC(TIMEDIFF(NOW(), CONVERT_TZ(LastUpdated, 'UTC', 'Europe/Amsterdam'))) < 1800) 
GROUP BY SensorName;
Categories
GNU/Linux

GNU/Linux Auto-mount NFS Share

Bash script to auto-mount NFS share when it is available (and not already mounted).

#!/bin/bash
ping -c 1 -n 192.168.1.250 > /dev/null
if [ $? -eq 0 ] && [ ! -d /mnt/nas1/directory ]; then
 sudo mount -t nfs 192.168.1.250:/mnt/nfsmountpoint /mnt/nas1
fi