Archive for the ‘Work’ Category

Windows PowerShell Execution Policies

Wednesday, May 28th, 2008

Windows Powershell sets its Execution Policy to Restricted by default, which states that PowerShell can only be used in interactive mode (no scripts will run.) Use the Get-ExecutionPolicy cmdlet to check which execution policy is currently in-force.

$ Get-ExecutionPolicy

The following execution policy definitions are from Microsoft’s website:

  • Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted – No restrictions; all Windows PowerShell scripts can be run.

To change the execution policy, use Set-ExecutionPolicy. The following will enable you to execute all PowerShell scripts.

$ Set-ExecutionPolicy Unrestricted

Windows PowerShell - Recursively delete files and directories modified more than ‘n’ days ago.

Thursday, May 22nd, 2008

I was recently tasked with writing a script that recursively deletes files and directories modified more than ‘n’ days ago - here’s the kicker - using Windows. Many people have accomplished this with long VB Scripts. I was hoping for a much cleaner solution, and decided to try Windows PowerShell . I am quite impressed with Windows Powershell’s capabilities.

The following script recursively deletes files and directories modified more than 16 days ago.

# prune.ps1
$sticky = (Get-date).AddDays(-16)
$backupDir = "B:\backup"
echo "Recursively deleting files and directories written before $sticky"
Get-ChildItem $backupDir -Recurse | Where-Object { $_.LastWriteTime -lt $sticky } | Remove-Item -Recurse

Note that you can change Remove-Item -Recurse to Remove-Item -Whatif to “pretend” to delete files, and display potential deletes on STDOUT. You can also specify Remove-Item -Confirm.

I created a scheduled task that runs a .bat file containing the following:
powershell.exe c:\scripts\prune.ps1 >> c:\scripts\logs\prune.log

To watch and or view the output of the script, specify the -noexit switch on the command line.
powershell.exe -noexit c:\scripts\prune.ps1

How to install NVIDIA drivers with Fedora 9

Tuesday, May 20th, 2008

Update: The current (173.14.09) stable NVIDIA driver works with Fedora 9. The following information is outdated and kept for archival purposes.

The latest stable NVIDIA drivers will not install when using the version of X.org that is distributed with Fedora 9. I was able to use NVIDIA’s beta 172.08 display drivers after a few manipulations.

Version 172.08 does not support ABI, so I placed the following in /usr/bin/startx

defaultserverargs="-ignoreABI"

I also commented the following from /etc/X11/xorg.conf

# Load "glx"

Fedora 9 and NVIDIA Drivers x86_64 Instructions

Download the appropriate beta driver

$ wget http://us.download.nvidia.com/XFree86/
Linux-x86_64/173.08/NVIDIA-Linux-x86_64-173.08-pkg2.run

Run the installer

$ sh NVIDIA-Linux-x86_64-173.08-pkg2.run

Edit /usr/bin/startx (for runlevel 3 users) and add the following:

defaultserverargs="-ignoreABI"

Edit /etc/X11/xorg.conf and comment the following:

# Load "glx"

Upgrade to Fedora 9

Friday, May 16th, 2008

I upgraded my primary workstation to Fedora 9 this week. Although the upgrade was mostly uneventful, I did struggle with a few annoyances.

The latest revision of openbox lacks a specific functionality that’s vital to my coherent work flow. It lacks the ability to hold down the left mouse button on the title bar, and use the scroll wheel to migrate the currently held window to the next or previous desktop. It was easy to roll back to a previous version from the Fedora Core 6 Extras repository.

Another annoyance is that konsole removed the –noxft switch in their latest revision, this allowed me to prevent my terminals from having anti-aliased fonts. I use the font Terminus (highly recommended, by the way) within my terminals, and having that anti-aliased is just unacceptable. I could just disable anti-aliasing across all applications, but then my browser and mail client would look terrible. I was able to solve this issue with ~/.fonts.conf.

The last issue I had was with pulseaudio. Sound was very soft, even with the speakers and alsamixer set to 100%. I removed alsa-plugins-pulseaudio, and things started functioning normally.

I tried KDE again this week, and was dissapointed (as usual.) It was quite sluggish, and seemed very kludged together. Maybe someone will develop a feature-full window manager that doesn’t require big iron to run before I’m a gray-beard. They would then have to convince me that it is indeed better to have all that eye candy, yeah right.

Software raid 1 - Failing and recovering a disk

Tuesday, April 29th, 2008

A software raid group disk failed in one of my servers yesterday.

The kernel was spewing SCSI errors:

kernel: ata2: status=0xd0 { Busy }
kernel: SCSI error : return code = 0×8000002

# mdadm --display /dev/md0
# mdadm --display /dev/md1

both reported a failed disk sdb*

The procedure to rebuild the md groups is as follows:

Replace bad disk (sdb in this scenario.) Note that if you do not bring down the server to replace the disk, be sure to “remove” the disk from the raid groups using mdadm.

# mdadm --remove /dev/md0 /dev/sdb0
# mdadm --remove /dev/md1 /dev/sdb1

Read the good disk’s partition table (sda in this scenario.)

# fdisk -l /dev/sda
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 fd Linux raid autodetect
/dev/sda2 14 19457 156183930 fd Linux raid autodetect

Install identical partition table on newly replaced disk. Create partitions that start and end on the same listed cylinders and are of type “fd.” Be sure to set the boot flag, and don’t forget to write the changes.

# fdisk /dev/sdb

Add partitions back to the appropriate raid groups.

# mdadm --add /dev/md0 /dev/sdb0
# mdadm --add /dev/md1 /dev/sdb1

Ensure the raid groups are rebuilding properly.

# mdadm --display /dev/md0
# mdadm --display /dev/md1

Searching and executing with find(1)

Thursday, April 17th, 2008

This afternoon I was faced with searching a directory tree for large files that have rotated within the last 24 hours - a symptom of a problem we were experiencing with a service.

Here’s what I put together quickly:

# find -iname name-\*.log -mtime 0 -exec du -sh {} \;

Explanation of the switches (from the find man page):

-iname pattern
Base of file name (the path with the leading directories removed) matches case insensitive shell pattern pattern

-mtime n
data was last modified n*24 hours ago.

-exec command {} \;
run the specified command on the matched files

It’s not complex (and probably not post-worthy,) but someone may find it helpful.

Nagios 2.6 and check_hpjd, Dell servers in an instrument rack, and network storage

Thursday, May 31st, 2007

Some of the jet direct emulation daemons on Kyocera Mitas are not compatible with the check_hpjd nagios plugin. I spent some time revamping our SNMP checks for certain printers - I have not yet fished, but am definitely making progress.

I ordered a server & rack extensions [plus round -> square hole converters] for one of our faculty members wanting to drop a Dell server in an instrument rack (25″ deep), this should be fun / interesting.

I’ve been spending a lot of time “putting out fires”, and resolving rt requests this week. Tomorrow night we’ll be migrating our storage from a local array to DCS network storage. This should be a major relief to our backup system.

Cfengine rocks my world

Friday, May 25th, 2007

dhcpd died on Thursday night, thankfully nagios paged me stating it couldn’t reach any of our networks. I’m not sure whether or not this (cfengine dieing) was due to campus losing one of their main DNS, but as a precautionary measure I told cfengine to check that dhcpd was running every 5 minutes, and restart it if necessary [and notify me]. I also wrote a cron script to manually check dhcpd status every 2 hours [just in case] and mail me.

We’re officially moving Danielle from Marquette tomorrow. I’ve rented a uhaul and Josh, Nancy, & Dave were nice enough to offer assistance.

Mutt 1.5.15, sidebar patch, rpmbuild

Wednesday, May 23rd, 2007

Craving more mutt functionality I was enticed by the mutt sidebar patch[1]. Instructions appeared simple enough, but it required a rebuild of mutt so I took the opportunity to build[2] an rpm. Having only made a few rpms in the past and wanting to do it in a manner that conforms with best practices, I used one of Josh’s spec files as an example. Red Hat’s How To documentation[3] was also helpful, although probably quite dated.

After building & installing mutt I appended the following to my .muttrc.

# Sidebar settings
set sidebar_width=20
set sidebar_visible=yes
set sidebar_delim=' '
color sidebar_new yellow default
macro index b 'toggle sidebar_visible'
macro pager b 'toggle sidebar_visible'
bind index K sidebar-prev
bind pager K sidebar-prev
bind index J sidebar-next
bind pager J sidebar-next
bind index O sidebar-open
bind pager O sidebar-open
bind index B bounce-message

I like the sidebar a lot, we’ll see how long it lasts.

[1]http://www.lunar-linux.org/index.php?option=com_content&task=view&id=44
[2]mutt-1.5.15-mtu.1.spec
[3]http://www.rpm.org/RPM-HOWTO/build.html

RHEL5 x86_64

Friday, May 18th, 2007

Josh & I spent some time this week upgrading our workstations to RHEL5 x86_64, other than a few oddities I believe we’re both happy about it. Exciting news - yum allows us to use public repos[1] with ease , this has really improved my x86_64 experience.

The rest of my week included [but was not limited to] the following:

  • Updating all of our Solaris & Linux krb5.conf files so that they no longer rely on dns for realm / kdc lookups
  • Auditing / updating our php.ini configuration files
  • Messing with samba shares
  • Setting up vncservers
  • Messing with the abyss (account exceptions, secondary logins, etc)
  • cron scripting

[1] Fedora 6 Extras