John Arends Techno babble

20Dec/10Off

Sending HTML email from a bash script

I had a situation where I needed to set up a cron job to send email reports based on the contents of a dynamically generated web page. I tried piping the output of wget and curl to the mail command, but each time the recipient would receive raw HTML instead of an HTML formatted email.

This was far more challenging than one would initially guess.

After a lot of googling and trial and error I came up with the following:

(cat <<EOCAT
Subject: ##Subject##
From: from@address.edu
MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline
EOCAT
curl https://www.edu/url/?view=123) | /usr/sbin/sendmail email@address

Posting it here may help someone else, or help me later.

Filed under: Linux, Scripting No Comments
7Sep/09Off

Trying to prevent lab users from forgetting their USB jump drives

One of the things I do at work is manage some university computer labs. Our student workers keep an eye on things, and noticed an increasing number of people were walking away leaving their USB jump drives still plugged into the computer. (It seems like most students call them a "USB" now, which to me is the same thing as calling a firewire hard drive a "firewire," but I digress...)

Anyway, I Googled around a bit, and wrote some VBscript code to add to our logout script to try to detect USB drives. It works pretty well, since we've had a huge reduction of lost drives piling up in our lost and found drawer since the script was put in place.

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Drives = FSO.Drives
strMessage = "Please unplug your USB Drive!" & vbcr & vbcr & "Please unplug your USB Drive!" & vbcr & vbcr & "Please unplug your USB Drive!" _
& vbcr & vbcr & "DO NOT FORGET!"
For Each DiskDrive In Drives
If DiskDrive.DriveType = "1" Then
If DiskDrive.IsReady = "True" Then
strMbox = MsgBox(strMessage ,48,"Unplug USB Drive")
End If
End If
Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Drives = FSO.Drives

strMessage = "Please unplug your USB Drive!" & vbcr & vbcr & "Please unplug your USB Drive!" & vbcr & vbcr & "Please unplug your USB Drive!" _
     & vbcr & vbcr & "DO NOT FORGET!"

For Each DiskDrive In Drives
	If DiskDrive.DriveType = "1" Then
		If DiskDrive.IsReady = "True" Then	
			strMbox = MsgBox(strMessage ,48,"Unplug USB Drive")
		End If
	End If
Next