Tuesday, August 3, 2010

Sending mail from command line or shell script

How to send mail from the Linux Command line (or shell script) using the mail command.

echo "This is the body of the email" | mail -s "Email Subject" recipient@domain.com -- -f senderaddress@domain.com


The -- -f section is used to plug in a sender address, otherwise the mail will be sent from your root or user account from the actual physical server name - e.g root@server1.domain.com


This comes in handy for notification of script execution, for example, jobs in the crontab. Placing this code immediately after the last command in a shell script will ensure relevant person(s) are notified when the script is called.

-n

Friday, July 30, 2010

Load Balancing - Never a dull moment

Currently doing some research into implementing an updated version of session aware loadbalancing for a specialized Moodle installation.

The solution I inherited with the system was Ultramonkey in a High Availability setup, but I figure I'm gonna throw in some dedicated loadbalancing in the new equation.

Updates to follow soon, as well as some more scripting!

Tuesday, July 20, 2010

Adding a virtual disk to a Linux Virtual Machine.

Needed to add another Virtual Disk to an existing machine in VMWare ESXi. Adding the disk to the VM Settings was the easy part and fairly straightforward. This particular guide is to get the Disk recognized on the actual Linux Server and mount it.


0. Login as root (Seeing a pattern yet?)

1. Identify the drive.
df -h  and take note of the entries.
cd /dev/
ls

By the process of elimination, the one in the list in /dev/ that is not part of the df -h listing is the culprit.


2. Create the filesystem
/sbin/mkfs -t ext3 /dev/xxx  where xxx is the drive identified in Step 1.


3. Mount the filesystem
 mount -t ext3 /dev/xxx /mnt/myfoldername where my folder name is - you guessed it!


4. Check to make sure it is there!
df -h


Woohoo!

-n

Monday, July 19, 2010

Backup, Backup Backup - never underestimate the value of it.

There I was, bitching about non-geek stuff, when *poof*, suffice it to say, never underestimate the value of a good backup strategy.


Situation:
One of the Moodle virtual servers that I manage failed and (conveniently) the RAID 5 with the backups went up in smoke as well. It literally just disappeared. Usually I prefer Hard disk backup to tape but in this case, hosting a server for someone else (bureaucratic favour), my preference turned around and bit me in the ass.

The meta-data on the Raid controller apparently became corrupt, with some sort of power blip (even with enterprise level UPS and generator backups) that happened just at the wrong time possible. Kind of like lightning hitting you in the dead of summer whilst you were casually walking in a field of lightning rods.

Anyhow, disaster aside, time to attempt either a recovery or a rebuild.

Part One - RAID Recovery.
In order to get the server to recognize the drives once more, the array needed to be deleted. Sounds scary, but technically the drives will not be wiped, per se. Then the array needed to be recreated using the same settings as its predecessor. Blind luck helped in this case, as the original guy who created the array took off, presumably because he got a premonition about this shitstorm and decided to flee.

So the Array got recreated and the server was able to see the 500 GB once again. YAY!...... well no. The 500GB appeared to be empty.

Time to see if we can work some magic.

Part two -  Attempted data recovery.
This will be done using UBCD for linux - two words. GET IT.
http://www.ultimatebootcd.com/download.html

Using the PhotoRec tool by CG Security, which is included on the CD, an attempt is currently being made to recover the data.

An update will follow soon.


*Update*

All we managed to recover was junk data. The server was rebuilt using an older backup. The client now understands the importance of a little request, like an extra HDD for backups.

-n

Tuesday, May 18, 2010

Update

Seems that the non-geek spell continues.
Currently working on some documentation, as well as:
Batch uploading users to myelearning (for manual accounts)
Batch creating courses (thanks to www.moodle.org)

Massive server changes coming soon, plus testing and deployment on VMWare ESXi, so plenty to write about in the upcoming weeks/months.

-n

Thursday, April 22, 2010

Windows Batch Script to remove spaces from filenames

Part of managing Moodle( for me) includes using a Windows Streaming Server to host large media files.
On several occasions, files have been sent with non-web-friendly filenames with spaces et al to be uploaded.

This script fixes that.

This is a windows batch script, which needs to be executed in the folder containing the files, and will replace the spaces and dots in the filenames. Simply copy the script below, name it remove_spaces.bat and execute in the folder needed.

Pretty handy stuff.

Credit to http://www.computing.net/answers/programming/batch-script-to-replace-filenames-h/16301.html

@echo off
setlocal enabledelayedexpansion
for %%j in (*.*) do (
set filename=%%~nj
set filename=!filename:.=_!
set filename=!filename: =_!
if not "!filename!"=="%%~nj" ren "%%j" "!filename!%%~xj"
)

**Updated on 05-07-2012
To remove underscores, use the following in place of lines 5 and 6
 ...
set filename=!filename:.=!
set filename=!filename: =!
...
 -n

Wednesday, April 7, 2010

Update

Seems like the geek stuff is on the back burner for the next few weeks.
Currently drafting some documentation and doing some planning for when I get new hardware. ;)
Moodle Networking is also on the cards...


-n