Advanced Shutdown Script – Part 2 (check for running services)

February 4, 2009

I’ve updated my “Advanced Shutdown Script” to now check for running services/processes before shutting down, this way the script will check and see if I a set of services are running or not, and if so exit.  The reason why I wanted to have this feature is because my NAS box runs backups and I wouldn’t want it to shutdown while running a backup. Thanks to this page: Check if program is running with bash shell script
It wasn’t hard to implement…
So here it is:

# 2/4/09
# Advanced Shutdown Script
# Ref –


   if ps ax | grep -v grep | grep $SERVICE > /dev/null
      echo “$SERVICE service is running: $(date)” >> /home/user/scripts/adv-shutdown.log
      echo “$SERVICE is NOT running: $(date)” >> /home/user/scripts/adv-shutdown.log

for IP  in $IP_LIST; do
   ping -q -c1 -w5 $IP
   if [ $? -eq 0 ]; then
      echo “$IP is alive: $(date)” >> /home/user/scripts/adv-shutdown.log

if [ $ALIVE -eq 0 ]; then
   echo “***ShutDown***  $(date)” >> /home/user/scripts/adv-shutdown.log
   echo “###########################” >> /home/user/scripts/adv-shutdown.log
   /sbin/shutdown -h now

see also:

You can put any number of services in the “SERVICE_LIST” variable separated by a space and it will check if any of them are running. i.e.:

SERVICE_LIST=’program1 program2 program3′

My backup program is called “mysecurebackup” so I only have that one in there right now.
Now I don’t need two separate lines in my ‘sudo crontab’ because the script will check and see if a backup is running, so my sudo crontab looks like this now:

# Run Advanced Shutdown script every 10minutes between 1-5:50am everyday
0,10,20,30,40,50 01-05 * * * /home/user/scripts/

Now to get back to work on a WOL script to power my NAS box up in the morning, stay tuned…

Advanced Shutdown Script – Powersaving

February 3, 2009

My NAS box is a power-hungry beast (Ubuntu 8.10 – p4 3ghz 4GB ram, 3x250gb RAID5, 200gb OS), and while I know I could go out and buy a readymade NAS, what would be the fun in that?, and I could also build a VIA or ATOM based system to do simple NAS tasks and replace the power-hungry p4, that would cost money, and I am trying to pinch-a-penny in these economic times…

So I usually leave the NAS box on 24/7 but I am starting to feel bad about that, and my electricity bill is making me feel it
But I need to leave the NAS on at night because it is my media server for my TV’s (XBMC)…
So I created 2 crontab lines:

# Weekdays
30 02 * * 1-5 /sbin/shutdown -h now
# Weekends
30 04 * * 6-7 /sbin/shutdown -h now

This is great, I just turn the NAS on in the morning when I need it… but this isn’t the optimal setting because I usually go to sleep well before 2:30am on weeknights and before 4:30am on weekends, however there are a few nights that I stay up past my bedtime :-P So I wanted to account for that in crontab. But on average I would have to say I usually go to sleep about 2-3hrs before these times.

So I gots-ta-thinkin and I figured that there must be a better way to handle this with a script, and after a quick question to Linux Questions: Need help creating an advanced shutdown script for power-saving?

And I got my answer and here is my new script:

# 2/3/09
# Advanced Shutdown Script
# Ref –


for IP  in $IP_LIST; do
   ping -q -c1 -w5 $IP
   if [ $? -eq 0 ]; then
      echo “$IP is alive: $(date)” >> /home/user/scripts/adv-shutdown.log

if [ $ALIVE -eq 0 ]; then
   echo “***ShutDown***  $(date)” >> /home/user/scripts/adv-shutdown.log
   echo “###########################” >> /home/user/scripts/adv-shutdown.log
   /sbin/shutdown -h now

see also:

Simply place this script in your /home/user/scripts directory (if ‘scripts’ directory doesn’t exist ‘mkdir scripts’ from your home directory) replace the IP_LIST ip addresses to match your own (leave a space in-between ip addresses), and replace all of the paths from ‘user’ to your local user account name, and remember to grant execute permissions by issuing “sudo chmod +x“.
This script will keep a log of shutdown tries in /home/user/scripts/adv-shutdown.log
Now just add this to the root crontab by running ‘sudo crontab -e‘ and enter the following:

# 2/3/09
# Advanced Shutdown Script
# Run Advanced Shutdown script every 10minutes between 1-5:50am Mon,Tues,Wed,Fri,Sat,Sun
0,10,20,30,40,50 01-05 * * 1,2,3,5,6,7 /home/user/scripts/
# Run Advanced Shutdown script every 10minutes between 2-5:50am Thurs (S3 Backup Night)
0,10,20,30,40,50 02-05 * * 4 /home/user/scripts/

see also:

I created two lines here because my NAS box backs up to Amazon S3 on Thursday nights, so I wanted to give it a little more time to work.

UPDATE – new script:Advanced Shutdown Script – Part 2 (check for running services)

How to setup a RAID5 software (mdadm) array w/ email notifications via Gmail – the easy way

December 7, 2008

Long title I know…
So I finally setup a NAS using Ubuntu Intrepid (8.10) Desktop, at first I was looking into using a pre-built solution such as FreeNAS or Openfiler but that limited the boxes ability to do other things (like serving up webpages using LAMP, etc.) besides I like having a Desktop GUI that I can play with if things go wrong.  So after figuring out what version of Ubuntu to use (Hardy for it’s LTS or Intrepid for latest and greatest) I decided on Intrepid.

My setup:
MoBo: Intel D865GBF Desktop Board
CPU: P4 3.0Ghz
RAM: 4x1GB G.Skill Sticks
VIDEO: FX5200 AGP card
IDE1: Seagate 250GB (ST380013A)
IDE2: Maxtor 250GB (Diamond Max Plus9)
SATA1: Western Digital 320GB (WD3200JD-22KLB0)
SATA2: Seagate 200GB (ST300822AS) – ***UBUNTU INSTALLED ON THIS ONE***

So I will be using IDE1,IDE2, & SATA1 for my RAID5 Array.

After a quick shout to the Ubuntu Community I found this wonderfully simple guide on setting up a RAID5 array using mdadm:

I did however run into one problem with the guide:

sudo mdadm –detail –scan >> /etc/mdadm/mdadm.conf

Which adds the following to my mdadm.conf file:

ARRAY /dev/md0 level=raid5 num-devices=3 metadata=00.90 UUID=13f95aef:9c364189:75b10d3a:87a53e2f

but after I’ve added that to the mdadm.conf and when I run the following:

sudo mdadm –examine –scan
mdadm: metadata format 00.90 unknown, ignored.
ARRAY /dev/md0 level=raid5 num-devices=3 UUID=13f95aef:9c364189:75b10d3a:87a53e2f

Notice: mdadm: metadata format 00.90 unknown, ignored.
So I had to remove “metadata=00.90” from my mdadm.conf file and I no longer get that message.
Anyone know why the metadata entry isn’t working?

And now on to setting up email notifications via Gmail – The easy way…

After spending literally hours trying to get postfix working and running into problems getting the SSL CA certificates working I gave up on postfix all together and started looking for an alternative, and after a few google searches I found one:

This guide walks you thru setting up exim4 to work with Gmail, and it works perfectly, the only problem I ran into with this guide was that you need to comment out the whole “login:” section of /etc/exim4/exim4.conf.template like so:

#Commented out so that Gmail’s Public_name can equal “LOGIN”
# driver = plaintext
# public_name = LOGIN
# Return empty string if not non-TLS AND looking up $host in passwd-file
# yields a non-empty string; fail otherwise.
# client_send = “<; ${if and{\
# {!eq{$tls_cipher}{}}\
# {!eq{PASSWDLINE}{}}\
# }\
# {}fail}\
# ; ${extract{1}{::}{PASSWDLINE}}\
# ; ${sg{PASSWDLINE}{\\N([^:]+:)(.*)\\N}{\\$2}}”
# Return empty string if looking up $host in passwd-file yields a
# non-empty string; fail otherwise.
# client_send = “<; ${if !eq{PASSWDLINE}{}\
# {}fail}\
# ; ${extract{1}{::}{PASSWDLINE}}\
# ; ${sg{PASSWDLINE}{\\N([^:]+:)(.*)\\N}{\\$2}}”
### end auth/30_exim4-config_examples

Now simply edit your /etc/mdadm/mdadm.conf file to read:

# instruct the monitoring daemon where to send mail alerts

Now you should be all set give it a test by running:

sudo mdadm –monitor –scan –test

And you should have an email within minutes :D

Ubuntu has problems with power saving (muti-display)

September 29, 2008

Using Ubuntu 8.04.1 (up to date)
I have a dual monitor setup, and I recently switched from “Separate X-Sessions” to a “TwinView” and now my monitors won’t go into standby/sleep (power saving) state. I’ve tried changing the settings in System>Power Management>Display> “Put display to sleep when inactive for” but no matter what I set it to (for a time limit) it NEVER goes into sleep mode. I’ve left the computer on for hours on end, and they never go into sleep. But when I switch from “TwinView” to “Separate X-Screens” the monitors go to sleep right on time, EVERYTIME.

p.s. I am NOT using Compiz (don’t know if that makes a difference or not).
System>Preferences>Appearance>Visual Effects = NONE.

Hopefully this will be fixed soon…

Checkout the bug reports
Ubuntu’s Launchpad:
Gnome’s BugZilla:

IOGEAR USB Net ShareStation – Possible Droboshare Replacement?

July 17, 2008

I came across a review for a new product called the USB Net ShareStation by IOGEAR. This little toy looks interesting enough, especially considering the fact that it allows one to use a 4port USB Hub to add more devices to your network via USB, this seems like a GREAT product. No more need for USB->Network print servers, and now I can use my external USB drives via my network. I am very interested in getting my hands on one of these badboys, and they are currently going for $50 shipped via eBay.

Couple of Con’s:

  1. 1 major downside, it’s not Linux compatible out-of-the-box, hopefully someone will hack the device drivers to work with Linux soon… If you know of anyone currently working on this please leave me a comment and let me know.
  2. 10/100Base-T port = Not Gigabit Ethernet

This got me thinking however what about using this as a replacement for the {currently} $200 DroboShare, this is essentially a DroboShare for 1/4 the cost, but would this work with the Drobo? Then of course this leads to a followup question of performance, which provides more throughput, the DroboShare or the ShareStation? I realize the DroboShare has a Gigabit ethernet connection, so this will probably be a major drawback, but I am curious to know what real-life experience/benchmarks between the too show…

Because this product is so new there aren’t alot of reviews that benchmark the ShareStation, but as I collect more information on this I will add it to this post. Please if you have any info on this, leave a comment.

Installing Ubuntu on a OLPC Xo – Part 1

July 10, 2008

Well thanks to the Ubuntu On OLPC XO wiki page I was able to successfully install Ubuntu on my OLPC.
I did however run into a few hitches.

1. Wireless Internet Connection

The wiki page doesn’t make reference to how to setup WEP wireless connection, it only mentions WPA (NETWORKING) so I had to do a bit of research: How to connect to wireless (WEP) in ubuntu?
turns out that the following does the trick:

iwconfig eth1 essid "mySSID" key mywepkey
sudo dhclient eth1

Now I had to figure out how to add this to a startup script so that it would automatically connect to my wireless router upon boot up: Automatic Wireless Connection (At Startup)?
All I had to do was add the following to /etc/network/interfaces

# Wireless Connection
iface eth1 inet dhcp
wireless-key hex-key
wireless-essid ssid

auto eth1

where hex-key = my WEP hex key & ssid = my routers wireless SSID

2. Mouse Problems

The Customizing Ubuntu for XO wiki page explains how to fix the tap-click issue and sensitivity, however the sensitivity issue I am having is that my mouse is too insensitive, My mouse pointer FLY’s across the screen when I move my finger, so instead of using the wiki’s recommened:
xset m 1/4 0
I am using:
xset m 25/20 0
and it is much better now.

3. Screen Saver

The first thing I noticed was there was no screensaver installed, when I went to Settings > Screensaver Settings, I got the following error: screensaver-settings-error
I was able to install xscreensaver, but I got another error every time I made a change to xscreensaver’s settings “Directory does not exist: /usr/share/backgrounds” a quick google search and I found a solution:
sudo apt-get install screensaver-default-images
Fixed :)

Part 2 of my setup woe’s comming soon…

How to move an Outlook 2007 DataFile ?

July 4, 2008

I decided to break free from Google Apps webGUI (a.k.a. Gmail) and start using Outlook to access my Google Apps domain account email.

I have an Outlook Profile that contains one Exchange account (Default) and 2 IMAP accounts. I am trying to change the datafile (pst) location for my two IMAP accounts from the default (C:\Documents and Settings\User\Local Settings\Application Data\Microsoft\Outlook) to another directory.

I’ve tried Google and I’ve read thru this page:
But there is a part on that page where I get lost…
It says:

  1. In the Tools menu, click Account Settings.
  2. On the E-mail tab, select the new e-mail account, and then click Change Folder.
  3. In the New E-mail Delivery Location dialog box, select the Inbox of the old .pst file.

But for me there is no “Change Folder” or “New E-mail Delivery Location” option???

What am I missing?

Edit 7-17-08:

I have found a possible solution, but I haven’t had time to try it out myself, I will post an update when I’ve confirmed this is working:

By default, Outlook places each Offline Folders (.ost) file and Personal Folders (.pst) file that it creates in the %userprofile%\Local Settings\Application Data\Microsoft\Outlook folder. This setting allows you to change the default behavior and store the files in any folder.

Open your registry and find the appropriate key below.

Outlook 2007 – [HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook]
Outlook 2003 – [HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook]
Outlook XP – [HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook]
Outlook 2000 – [HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook]

Create a new REG_EXPAND_SZ (Expandable String) value called ‘ForcePSTPath’ and set it to equal the full path of the required personal folder directory (e.g. “C:\Mailbox”).

Restart Outlook for the change to take effect. and if this does not work.. try restarting your cmputer aswell.


You can also move the current .pst files to the new location using the following method.

>Open the Outlook.
>Click on File > Data Management File.
>Make a note of the path where the Outlook.pst file is stored or saved.
> Close the Outlook and copy the folder to some other location and then reopen outlook.
> use the same procedure to Add the new pst file from the new location and remove the old PST that is there..

It should work fine.. You can follow any method that you think it is useful..

Again, I have not tested the above, so proceed with caution. I will report back when I’ve had a chance to confirm the above is a working solution. Thanks for your patience.


Get every new post delivered to your Inbox.