Executing CakePHP script using Windows Scheduled Task

In Windows adding a scheduled task is just not as straight forward as adding a CRON job using Linux. (Don’t get me started on troubleshooting a Windows Schedule Task that did not run for some reason.) However, it is not so difficult once you get it figured out. Here is what I did:

In this case I wanted to run a CakePHP script as a CRON job, or more accurately, as a Windows Scheduled Task since this customer insisted I create the application and use a Windows server. (I used XAMPP, so it wasn’t too bad.)

In order to run the script and take full advantage of the models in CakePHP it required that I use the CakePHP shell. Luckily the CakePHP developers created a ‘cake.bat’ script that enables this to happen on a Windows machine.  Normally on a Windows or Linux server you can navigate, via command line, to the ‘app’ folder and execute the ‘cake  name_of_script’ command, but using Windows Scheduled Tasks you need to execute the bat file.

Windows Scheduled Task Settings:
Run: C:\path\to\cake.bat  script_name {without the extension .php}
Start in: C:\path\to\app\folder
Run As: type in the appropriate users

Then of course you will need to go to the Schedule tab and set in the schedule you desire for your script.

Here is a screenshot: (you can see the default folders for xampp were used)

IMPORTANT: This entire process assumes that you have already created your script and placed it in the appropriate directory “/app/vendors/shells/{name_of_script.php}”.  It also assumes you understand how to create a cronjob for CakePHP to use.  (see below for a sample)

Sample content of ‘script_name.php’:

class ScriptNameShell extends Shell {
 
	var $uses = array('model1','model2');
 
	/**
	 * the main function is kicked off like a contructor
	 *
	 */
	function main() {
		echo 'Doing something.';
 
		$callingSomething = $this->otherFunction();
 
		echo $callingSomething;
	}
 
	function otherFunction() {
		$content = 'This is content from otherFunction.';
 
		return $content;
	}
}

Finding Duplicates using SQL

While migrating old data to a new database schema I was unable to activate a PRIMARY KEY on the legacy_customer_id field because there were duplicates. It turned out that the old application did not clean the data really well, and it allowed duplicates to be created where one of the customer_ids had a space character making it unique.

I used the following query to test for others:

SELECT
    customer_id,
    COUNT(customer_id)
FROM
    customers
GROUP BY
    customer_id
HAVING
    (COUNT(customer_id) > 1);

This allowed me to find all customer_ids that had duplicates and clean things up.

Virtualmin error while installing on Ubuntu 10.4

While I am very comfortable using Linux via a command line shell, I think all of us can admit that occasionally we need to look up a command or two due to non-regular use. Because time is short, and can be expensive when we have tons to do, I usually install Virtualmin (which also installs Webmin) on most of my servers. It is simply easier to login and get things done quickly.

Well, as I was setting up a new server at my hosting provider today and installing Virtualmin I ran into a little problem. The server was a fresh install, and Virtualmin would not install on my fresh load of Ubuntu 10.4 (which is a supported OS by Virtualmin). Instead I received the error:

... No apport report written because the error message indicates its a followup error from a previous failure
 
pkg: dependency problems prevent configuration of virtualmin-base:
virtualmin-base depends on dovecot-common; however:
Package dovecot-common is not configured yet.
virtualmin-base depends on dovecot-imapd; however:
Package dovecot-imapd is not configured yet.
virtualmin-base depends on dovecot-pop3d; however:
Package dovecot-pop3d is not configured yet.
dpkg: error processing virtualmin-base (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
dovecot-common
dovecot-imapd
dovecot-pop3d
virtualmin-base
 
FATAL - 2011-09-01 00:07:13 - Fatal Error Occurred: Something went wrong during installation: 0
FATAL - 2011-09-01 00:07:13 - Cannot continue installation.
FATAL - 2011-09-01 00:07:14 - Attempting to remove virtualmin repository configuration, so the installation can be
FATAL - 2011-09-01 00:07:14 - re-attempted after any problems have been resolved.
FATAL - 2011-09-01 00:07:14 - Removing temporary directory and files.
FATAL - 2011-09-01 00:07:14 - If you are unsure of what went wrong, you may wish to review the log
FATAL - 2011-09-01 00:07:14 - in /root/virtualmin-install.log

Well, after some Google searching I determined that the problem may be related to a bad hostname set on the server. This was a little confusing because the install also detected this at the beginning and asked me what I would like the hostname set to. However, it appears that providing the hostname did not make a difference because Virtualmin was not able to set it.

I first tested the hostname to see if this was the problem by doing:

$ hostname -f

Sure enough, it warned that the hostname was a problem. So here is how I fixed things:

First, I had to set the hostname on the server (I use sudo, but you could be logged in as root or change to superuser with su.):

# sudo vi /etc/hostname

In vi you would edit the hostname to be a fully qualified domain name (FDQN) and saving. (click “i” to enter insert mode, then “esc” to stop, and hit “ZZ” to save and close. Note: these are capital “ZZ”.)

Second, this requires a restart of the hostname service to apply the change. (Note: you can use ‘restart’ instead of stop and start.)

# sudo /etc/init.d/hostname stop
# sudo /etc/init.d/hostname start

Third, I had to then update my hosts file to also reflect the change. (click “i” to enter insert mode, then “esc” to stop, and hit “ZZ” to save and close. Note: these are capital “ZZ”.)

# sudo vi /etc/hosts

IMPORTANT: If you do not include the “shortname” after the hostname applications will still not consider this a FDQN.

Example of what should be in the hosts file when you are done:

127.0.0.1     myhome.domain.com myhome

After doing these three steps I was able to successfully install Virtualmin with no issues.

Tether Android to Ubuntu for free Internet

A couple of weeks ago I was without Internet (thanks to AT&T), and was forced to go to Starbucks to check email and commit work I had done. While I like going to Starbucks, it was not the best working situation for someone who works from home.

Since I have an Android (HTC Evo) I thought about USB tethering the device to my laptop and Internet sharing, but Sprint hits you with a $29.95/month fee to use that option.  Since I am completely able to work locally without a connection to the Internet, I decided to tough it out and wait until AT&T figured out their mess and got me turned back on.

Fast forward a couple of weeks later… (yes, I am back on the net)

I found some neat applications for my phone that enable someone to bypass the tethering options that Sprint charges for.  One popular application is PdaNet, but it is limited to Windows and Mac. (For those who are still limited by those two platforms, give PdaNet a try.)  Another application I stumbled across called EasyTether has Linux support, so I gave it a try. (I am actually writting this blog post while using it)

The application for the Droid was available on the Droid Market Place, and their website has the Ubuntu file available for the PC connection. http://mobile-stream.com/easytether/drivers.html

I installed the “Lite” version from the Droid Market Place (FREE!!! but limits you to non-SSL pages, unless you pay the $9.99 for the full version) The application walks you through the couple of simple steps needed to use it, and even gives you the address above to get your Windows/Mac/Ubuntu/Fedora up and running.

Once I installed the DEB file on my laptop, after downloading it, all I had to do was connect my phone to USB and open the connection via command line.

The command to link up is:

easytether connect

Now the next time I am without Internet I am ready. :)

Categorized under: OS, Quick Tips, command line, linux, shell, terminal

Empty file contents at command line on Linux system

As is often the case I needed to accomplish something, so I tinkered until I figure it out. I had a web site that I recently moved from a PHP 5.2 to 5.3 enabled server. It became a problem when I realized my error logs had filled up with 600 MB of deprecated function messages, and after fixing the issues I wanted to clear out the logs.

While there are a few methods of doing this, I wanted to keep it simple. Here is the command I used:

> filename.log

The greater than symbol is the command which pipes nothing to the file, thus clearing it. This cleared up the file quickly, and left the permissions and filename in place.

Categorized under: Dreamweaver, cakephp, php, programming, windows

CakePHP and Dreamweaver opening ctp files

I have been working with some web designers recently who do not have a lot of PHP coding experience, but fully understand HTML and CSS in code view using Dreamweaver. So, to help them transition projects to using PHP, or more to the point using the CakePHP framework, I have been making preparations to move in that direction.

The hurdle, after setting up the base site using the framework, was to get .ctp files rendering in Dreamweaver. (Their editor of choice.)  Initially Dreamweaver does not understand what the ctp file extension is, and how should it syntax highlight the code.  So we help Dreamweaver out by editing a few of its configuration files. (Note: I only have Dreamweaver CS3, otherwise known as version 9, so I am not sure how it affects later versions of Dreamweaver.  Hopefully future versions of Dreamweaver may already understand the ctp file extension.)

First, we edit a Dreamweaver base configuration file located at “C:\Program Files\Adobe\Adobe Dreamweaver CS3\configuration\Extensions.txt” and alter 2 lines by adding the CTP file extension as follows:

...,INC,JAVA,EDML,MASTER,CTP:All Documents

The very first line should look as above at the end.

PHP,PHP3,PHP4,PHP5,TPL,CTP:PHP Files

The PHP Files line, which was line 16 for me, should look as above.

Second, we do the exact same thing to the user configuration file located at “C:\Documents and Settings\{user}\Application Data\Adobe\Dreamweaver 9\Configuration\Extensions.txt”. I am not sure why we need to edit the same file in both locations, but that is what is required. (One would think that editing the user configuration file would be enough since it should cascade over the base configuration, but it does not work that way.)

For Windows 7, there is an additional file that needs to be updated the same way at “C:\Users\\AppData\Roaming\Adobe\Dreamweaver 9\Configuration\Extensions.txt”. (Note: For later versions of Dreamweaver there is another folder level under Configuration called “en_US” that contains the Extensions.txt file.)

Fourth, we now need to push Dreamweaver to what type of file ctp is, and how should it be rendered. We do this by editing another configuration file located at “C:\Program Files\Adobe\Adobe Dreamweaver CS3\configuration\DocumentTypes\MMDocumentTypes.xml”. What we are looking for is around the 75th line where it reads “servermodel=PHP MySQL”.

winfileextension="php,php3,php4,php5,ctp"
macfileextension="php,php3,php4,php5.ctp"

Add the ctp extension to the comma separated list as shown above.

Your done! But first you must check one more thing. After you start Dreamweaver, open the “Edit->Preferences” and look at the “File Types/Editors”. Make sure that “.ctp” is not in the list to “Open in code view”, otherwise Dreamweaver will not allow you to use Design View with ctp files. (Note: Design View is not truly useful since Dreamweaver will still not use the Layout file. But you can still assign “Design Time” styles to render views.)

Categorized under: cakephp, php, programming

CakePHP says An Internal Error Has Occurred.

Recently I had the wonderful experience of CakePHP informing me that “An Internal Error Has Occurred”, with no more indication of what the problem could be. After digging around the CakePHP code I quickly found out that this code is pretty much used for any 500 browser error.  So I started the process of elimination:

  1. The site was working correctly.  I know this because most pages on the site came up just fine.  The error was only on certain pages.
  2. It was not caused by the page not existing on the server.  The controller, action, and models were all named correctly.  I know this because the page was working correct a week ago, and because I did a sanity check to ensure nothing had changed in this area.
  3. I checked to ensure the .htaccess had not been deleted, changed, or renamed.  All was OK here.
  4. I checked the CakePHP logs.  These exist in the ‘app/tmp/logs/’ directory.  There were NO errors reported, and no debug entries as well.
  5. I checked the /var/log/messges’ and found no errors reported there.
  6. I checked the /var/apache2/{log_file_name}’ and found no errors there.

Everything should have been working, according to the settings and log files, so why was I still receiving this internal error message?

How I solved it:

Finally, I got tired of playing around and simply edited the CakePHP code to output $params array to see the raw reason for the error.  I did this by editing the ‘cake/libs/error.php’ file and adding the following around line 176 in the “error500″ function as the first two lines as follows:

print_r($params);
die();

This gave me a simple array that clearly informed me I was missing a table in the DB that was deprecated. From there I quickly found the entry in the model that was still trying to link to the deprecated table. I cleaned up the offending model, and now all is well with the world again.

Categorized under: Android, Quick Tips, google, htc evo

HTC Evo com.htc.bg problem

So about a month ago my HTC Evo started giving me an error message almost every time I looked at the phone. The message was “The process com.htc.bg has stopped unexpectedly. Please try again.” or something similar to this. It didn’t seem to cause any problems, so I simply clicked the “OK” button and moved on. However, it was a pain the butt to do this almost every time I tried to do something on the phone.

There was nothing that jumps out at me as a single cause for this new error. Some on the web stated it was due to the 2.2 upgrade, but I upgraded to 2.2 almost 3 months prior to getting this error so I know that was not it. I tried un-installing a few apps that I installed around the time it started, but that didn’t work.

I searched the web and found many solutions ranging from turning off the Facebook auto sync, turning off the weather auto sync, and other such things. But basically I think it is a shame to turn off features on the phone to fix a problem. I mean why would I buy a super cool phone, then turn off features that caused me to buy it in the first place to solve a problem? It just didn’t make sense to me.

A couple of days ago I finally had enough and decided it was time to back up the contacts and other data to the SD card and reload the phone to the factory settings. Doing it was easy. Simply click the Menu button, then select Settings. Then I selected the SD & phone storage option, and at the bottom is the Factory data reset. From there you follow the prompts and watch the phone reboot a couple of times. After about 10 minutes I had a brand new phone again.

Of course it took me a bit longer to reload the apps i wanted, and restoring the contacts. But it is done.

So, I still am not sure what caused the error, but it is not happening any more. Problem solved, and I still have all of the nice features I wanted without disabling them.

Categorized under: Quick Tips, css, html, programming

Centering an HTML table with CSS

As you may have noticed, the table align=”center” attribute has been deprecated. So how is one supposed to center a table in an HTML page? The answer is with CSS. However, this is not as straight forward as you would think. Basically we now need to inform the browser to put the same amount of empty space on either side of our tables. Here is how to do it:

The inline method

<table style="margin:auto;">

Or if you are using an attached stylesheet you can do it with either classes or the ID method, or by further defining the table tag.

Here are some lines from a CSS stylesheet showing all three methods (you only need to use one of them, so choose what works best for you)

/* this will define the table tag */
table { margin:auto }
 
/* this will define an ID to assign the style to */
# table_align { margin:auto }
 
/* and lastly this is a css class that can be used */
.table_align { margin:auto }

Now, here is the html to make use of these three methods

<table class="table_align" id="table_align">

NOTE: Using “margin:auto” is a bit of overkill since it is basically affecting the margin on all 4 sides of the table in some way. You could center the table more precise by using the margin-left:auto and margin-right:auto and setting two properties in CSS. However, I usually find that the regular margin:auto generally does the job when the top and bottom are not a concern.

Unfortunately IE (Internet Explorer) once again is different and chooses not to recognize any of the methods above. So you will be forced to do one of two things.

  1. Add the margin:auto style to your “body” tag OR
  2. Resort to still using the align=”center” attribute for your tables to satisfy IE

Examples:

<body style="margin:auto">
 
<table align="center">

I do not like the previous two examples, but sometimes you gotta do what it takes to reach your entire audience.

Categorized under: Quick Tips, bash, linux, shell, terminal

Setting larger terminal size when launching

Have you ever noticed that when opening a terminal screen in Linux it is very small? Who can work like that? AND in order to do anything I need to drag the corner of the window to make it larger, which is time consuming and drives me crazy because I am opening and closing my terminal screens many times each day.

So, here is a screenshot of how small the terminal screen is when initially launched:

Tiny terminal window on launch

The fix is very simple.  Right click on the launcher for terminal and select “Properties”.  When that dialog opens you are going to edit the Command to set the geometry of the window to be BIGGER.  I personally like my terminal to be 175×50, you can vary the size as you wish.

So, here is the new Command: (175 is the width and 50 is the height)

gnome-terminal --geometry 175x50

Now when my terminal screen opens it is much better:

Bigger Terminal Size

Enjoy!

Install APC (alternative PHP cache) on RedHat RHEL 5

After attending php|tek 2009 I decided it was finally time for me to play with APC, and at least install it on a server to see what all of the excitement is about. After all, if it is good enough for Facebook it must be pretty beneficial, right?

According to the documentation the following command is what it takes to install:

pecl install apc

However, then I tried this I quickly received an error stating “phpize: command not found”. So after a little searching I discovered that I needed to install php-devel.i386 to enable pear to install packages. (You may also need to install autoconf, automake and libtool to do phpize. I must have already had them installed.)

sudo yum install php-devel.i386

Note: I used sudo, but you can also use su to change to the root user and then run the command as root.

Now after installing that, which also installed a couple of dependencies and updated a couple of other applications, I figured I would be all set. To the contrary I tried the install apc command again and I received one prompt asking:

Use apxs to set compile flags (if using APC with Apache)? [yes]:

I received a new error after answering “yes” :

Sorry, I was not able to successfully run APXS.  Possible reasons:
 
1.  Perl is not installed;
2.  Apache was not compiled with DSO support (--enable-module=so);
3.  'apxs' is not in your path.  Try to use --with-apxs=/path/to/apxs
The output of apxs follows
/tmp/tmpArfGXr/APC-3.0.10/configure: line 3196: apxs: command not found
configure: error: Aborting
ERROR: `/tmp/tmpArfGXr/APC-3.0.10/configure --enable-apc-mmap=yes
--with-apxs' failed

After a few minutes of searching I found a post somewhere that informed me that httpd-devel.i386 also needed to be installed.

sudo yum install httpd-devel.i386

Once the package installed, along with a few more dependencies and updates, I was then ready to try again. This time all went well, and APC was installed.

One final step was to activate it in the php.ini file. I added the following:

extension=apc.so
apc.enabled = On

Next I was ready to restart Apache and see APC in action:

sudo /etc/init.d/httpd restart

After creating a quick phpinfo() call I could now see that the APC module was indeed active. Once I copied the apc.php file that comes with the APC install files into a web accessible directory (preferably password protected) I was clearly able to see stats associated with APC.

There is much more you can do with APC settings, etc. However, that is another story for another time. Here are a couple of links to help get you started though.
C7y Tutorial
Pecl page

Categorized under: Quick Tips, linux, php, programming

Installing mhash on RHEL 4 and PHP 4.3.9

Recently I had a customer that was receiving errors from an Authorize.Net web submit form in their shopping cart. The error simply stated:

“The gateway no longer supports the requested method of integration.”

While doing some digging I found that they were using a very old web submit method that Authorize.Net no longer supported. There were two ways to fix the problem:

  1. Change to AIM method of submission, which required an SSL certificate that the client did not have.
  2. Change to SIM method of submission, which required either PHP 5.1.2 installed to use the hash_hmac function, or for PHP 4.3.9 it required that mhash be installed on the server.

Since the client did not want to spend the extra cash for the SSL certificate, and I could not install PHP 5.1.2 because I had too many other clients on the server that were not ready for the upgrade, I decided to do some searching for a way to install mhash.

It turned out that the Red Hat repositories did not carry php-mhash for RHEL 4, so this meant I needed to look in other areas. After reading many different blog and BB postings saying that it required an install, then a recompile of PHP I started to get a little worried. I did not look forward to recompiling PHP.

Finally I found some posts that brought a ray of hope. There are RPMs available to install php-mhash without the PHP recompile, but it required that libmhash be installed first. Here are the steps I followed:

  • I went to http://dag.wieers.com/packages/libmhash/ and downloaded the newest version of libmhash for my server.
  • Then I installed using the following to satisfy dependencies of mhash:
    rpm -iv libmhash-0.9.1-1.rhel3.dag.i386.rpm
  • Next I downloaded the php-mhash by using:
    wget ftp://rpmfind.net/linux/sourceforge/p/ph/phprpms/php-mhash-4.3.2-19.ent.2.i386.rpm
  • I followed that by installing it using:
    rpm -iv php-mhash-4.3.2-19.ent.2.i386.rpm

After following those steps I created a phpinfo script to see that everything went well:

<?php
phpinfo();
?>

I could now plainly see that mhash was installed perfectly, and with further tests I confirmed it was working.

Categorized under: Hardware, Quick Tips, Ubuntu, linux

Ubuntu can mount ISO files, and IMG files after converting them to ISO

Today I needed to create an OEM Microsoft Office 2007 CD and found that I could download the disks directly from the Microsoft site. However, the files that I downloaded were in IMG format. At first I was puzzled, but quickly (via Google) found out that they were essentially ISO files. However, I did not quickly find anything in Ubuntu that would burn an IMG to disk.
Diligent searching finally revealed that while there were not really ways to burn an IMG to disk, or mount an IMG file directly, there is a tool called ccd2iso that converts the IMG to ISO format.

First I had to install the ccd2iso package via Synaptic package manager, or I could have used ‘sudo apt install ccd2iso’.

After installing this I could simply run the following command from terminal:

ccd2iso myfile.img myfile.iso

The same methods can be used for other image type files:
mdf2iso -> myfile.mdf
nrg2iso -> myfile.nrg

Now I have a regular iso file that can be used to serve our purposes by burning to disk or mounting:

sudo mount -o loop myfile.iso mountname
 
or
 
sudo mount -o loop -t iso9660 myfile.iso mountname

The .nrg files can also be mounted in this manner without converting to ISO by using:

sudo mount -o loop,offset=307200 myfile.nrg mountname

NOTE: if this doesn’t work and you get an error like: “Unrecognized sector mode (0) at sector 0!” it may be due to the limitations of the ccd2iso. In my case the MS Office disk had multiple sessions, and I could not convert it to ISO.

Another post I found on Ubuntuforums said to try the following:

growisofs -dvd-compat -Z /dev/dvdrw=dvd.img

Where /dev/dvdrw is your dvd/cd burner.

FOLLOWUP:
The IMG file I had from Microsoft was a multi-session disk so I was not able to use the steps above. However, when I simply changed the file extension to ‘.iso’ it worked fine. There seems to be very little difference between IMG and ISO.

Categorized under: OS, Quick Tips, Ubuntu, linux, mac, programming

Finding a text string inside a file on a Linux server

It never fails that I find myself hunting for a way to search for a particular text string in files.  Usually I know the file, but often times I also find that I am completely unsure what file contains the string.  Or while I am writting some code I need to find how many files use a certain function.

I know that using grep is the best way to search on a Linux server, so I start there.  Here is the command syntax:

grep "text string to search for" /path/to/search

Examples
To search for a string called “myFunction” in all text files located in /var/www/html/*.php use:

grep "myFunction" /var/www/html/*.php

To search recursively in all sub-directories you would alter the command by adding the -r option:

grep -r "myFunction" /var/www/html

Now you have probably noticed that grep prints out the matching lines containing your string, but you may also need the filenames of the files containing the string instead. You can use the -H option to narrow the output the filename followed by the line containing your search string, like so:

grep -H -r "myFunction" /var/www/html

This would output something like:

...
your_file.php: line containing myFunction
..

To print out just the filename you can cut command like this to clean the output further: (Note the one after the f, not an L)

grep -H -r "myFunction" /var/www/html | cut -d: -f1

The new cleaner out put would be like:

...
your_file.php
...

Backup files from Linux to a Windows server

Ok, this may be my last disaster recovery and backup blog for a long time. As you can probably tell from the title this blog entry is all about keeping backup strategies as cheap as possible.

My strategy is to backup all of my Windows and Linux servers to one central Windows server that is running a Tivoli backup agent. All of my servers are hosted elsewhere, and since it costs $99.00 per server to backup I am getting the most for my money by only backing a single server to tape/SAN. However that single server carries all of the files that need to be remotely backed up to tape/SAN.

My earlier posts show how to backup the Windows servers:
Windows backup bat script using xcopy

Also, how to backup the Windows Domain Controller:
Backup Windows Domain Controller using NTBACKUP via cmd

And I also showed how to backup a Linux server to a local file:
Linux backup using CRON to local directory

Now I will show how I moved the files backed up on the Linux servers to the Windows server prior to tape/SAN backup. I have decided to use Samba and mount a directory pointing to a shared folder on the Windows server. Lets begin:

Linux backup using CRON to local directory

As many have pointed out I am on a backup and disaster recovery kick lately. Some would say that it is about time, others are simply glad to see that data is now being backed up. I have found that it is easiest to zip up files on a local machine prior to moving them to a final destination. So lets get started:

I have multiple Linux servers with many websites on each, as well as database. So I created a script that simply tar’s the files, then gzips them with the date in the filename for archiving.

Here is the file named ‘backupall.sh’ that I save in a place reachable by the user I will use to schedule this cronjob:

#!/bin/sh
date
echo "############### Backing up files on the system... ###############"
 
backupfilename=server_file_backup_`date '+%Y-%m-%d'`
 
echo "----- First do the sql by deleting the old file and dumping the current data -----"
rm -f /tmp/backup.sql
mysqldump --user=mysqluser --password=password --all-databases --add-drop-table > /tmp/backup.sql
 
echo "----- Now tar, then zip up all files to be saved -----"
tar cvf /directory/to/store/file/${backupfilename}.tar /home/* /var/www/html/* /usr/local/svn/* /etc/php.ini /etc/httpd/conf/httpd.conf /tmp/backup.sql /var/trac/*
gzip /directory/to/store/file/${backupfilename}.tar
rm /directory/to/store/file/${backupfilename}.tar
chmod 666 /directory/to/store/file/${backupfilename}.tar.gz
 
echo "############### Completed backing up system... ###############"
date

Backup Windows Domain Controller using NTBACKUP via cmd

Backing up your servers for disaster recovery these days much include your Domain Controller if you are utilizing a Windows Active Directory to manage your users. To do this is easy using a tool that comes installed on all Windows servers called NTBACKUP. Of course you can launch the GUI by entering NTBACKUP from the run or command line. However, this does not make automated backup work very well. So here is the .bat file that I use to execute it via Windows Scheduled tasks:

@echo off
:: variables
set logfile=D:\backup_log_file.txt
 
echo %Date% # # # Backing up system state containing: local Registry, COM+ Class Registration Database, System Boot Files, Certificates(if certificate server installed), Cluster database(if installed), NTDS.DIT, and SYSVOL folder >> %logfile%
ntbackup backup systemstate /J "System State Backup Job" /F "D:\system_state_backup.bkf" >> %logfile%
 
echo %Date% Backup Completed! >> %logfile%

(NOTE: I am doing this backup via an internal network and using a user account that exists on both systems. Security may dictate that you handle this differently based on your circumstances.)

After the file is executed by Windows Scheduled Tasks you will then be left with a file that is ready to backup somewhere. I do this by making a copy to another server by using the methods covered in a previous blog post at Windows backup bat script using xcopy.

Categorized under: MSSQL, Scheduled Tasks, servers, windows

Windows backup bat script using xcopy

Recently I had the need to create a bat script that could be executed by the Windows Scheduled Tasks. The purpose was to copy files from one server to another as a cheap way to backup files created by MSSQL backing up the databases. Here is the .bat file contents (cleaned up to protect sensitive data):

@echo
:: variables
set sourcedrive=D:\
set backupdrive=\\servername\d$
set backupcmd=xcopy /s /c /d /e /h /i /r /y
 
echo # # # Moving files
%backupcmd% "%sourcedrive%\directory_to_backup" "%backupdrive%\directory_to_store_backup"
 
echo # # Moveing Complete!

(NOTE: I am doing this backup via an internal network and using a user account that exists on both systems. Security may dictate that you handle this differently based on your circumstances.)

Notice that for the backupdrive I am calling another Windows server and using the d$. This would require that the Windows Scheduled Task be executed using a user that is trusted on both machines. Also you could specify a local directory on the same server if you did not need to copy the files to another server.

Categorized under: Quick Tips, Ubuntu, applications, linux

UltraEdit on Linux and MAC…finally ! ! !

I received an email that just made my day. It was the announcement that UltraEdit will finally be available on Linux! The screenshots show it on Ubuntu, and they say there will also be a version for MAC. (Initially it will only be packaged for Ubuntu with tar balls for the others, but soon there will also be packages for Suse, and Redhat) And it is very close to release, supposedly Alpha in April 2009.

UltraEdit on Ubuntu

UltraEdit on Ubuntu

You can find out more on the Blog Post, or you can see the Formal Product Page.

Categorized under: OS, Plesk, apache, linux, servers

Redhat, Plesk, named, and chroot oh my!

Well once again I performed my updates via Redhat up2date, and once again I lost all name services on a server.  This time I thought I would post my fix, since it was the same as last time.

There was an update issued by RHN this evening which updated the bind-chroot rpm. As part of it’s post install script it will attempt to relocate any zone files that may be located outside of the chroot into a chrooted directory in /var/named/chroot.

Since PSA implements a chroot for named outside of this package the nameserver files will be relocated to a path like…

/var/named/chroot/var/named/run-root/var/named/

This will of course break named’s ability to startup.

simply remove the bind-chroot rpm and re-link the /etc/named.conf file to the right location.

rpm -e bind-chroot
ln -sf /var/named/run-root/etc/named.conf /etc/named.conf
/sbin/service named restart

You should be good to go at that point.

Categorized under: Databases, MySQL, OS, Quick Tips, apache, linux, servers

Get SSL running on Apache (CentOS)

I was playing with a new virtual server that had CentOS installed on it recently, and wanted to get SSL working for Apache.  Since I was only setting up a development server I really didn’t need to purchase a certificate and decided to use a self-signed certificate.  Here is what I did:

First I needed to get ‘make’ and ‘mod_ssl’ running to allow for this. (I use sudo but you could login as su)

sudo yum install make
sudo yum install mod_ssl

Next I did the following steps:

  1. Go to /etc/pki/tls/certs
  2. Run the command sudo make mycert.pem
  3. Enter the information you are prompted for about country, state, city, host name etc, your certificate and key has been created
  4. Now edit /etc/httpd/conf.d/ssl.conf and update the following items:
    • SSLCACertificateFile /etc/pki/tls/certs/mycert.pem
    • SSLCACertificateKeyFile /etc/pki/tls/mycert.pem
  5. I was forced to create a symbolic link for the SSLCACertificateKeyFile as follows: (I think this was supposed to happen automagically.)
    • I went to /etc/pki/tls and created the symbolic link using the next line.
    • sudo ln -s certs/mycert.pem mycert.pem
  6. Restart Apache (/etc/init.d/httpd restart)

There, now you have a self-signed certificate for your apache virtualhosts.

TinyMCE URL rewrite problem editing emails (kinda solved)

TinyMCE has a habit of rewriting the URL for images, etc.  However, this becomes broken when using TinyMCE to edit things like emails.  The relative path is totally useless in an email because the email is not being viewed from the server like a webpage would be.

To fix this I searched the tiny_mcs.js and found that TinyMCE had two settings in the tiny_mce.js file that are boolean flags (true,false or 0,1) dealing with URL’s. The variables are relative_urls and convert_urls, and by default they are set to true, or 1.

After changing these setting to false (or zero) I have not had any further problems with using TinyMCE to edit email content.

Categorized under: Hardware, OS, Quick Tips, linux, servers

Hard disk usage from command line on Linux

From the command line I have found many great tools for system management, but really needed to dig into ways of tracking hard disk usage on Linux without the aid of GUI tools. Google to the rescue! I found a few places with great tips and hints on how to do this, but one article on Linux.com came in very handy. Here were my findings:

The df utility displays the disk space usage on all mounted filesystems. The -T option prints the filesystem type as well. By default, df measures the size in 1K blocks, which could be a little difficult for a desktop user to decipher. Use the -h option to get more understandable output:

$ df -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/hda6     ext3     20G  9.3G  9.1G  51% /
/dev/hda7 reiserfs     13G  2.1G   11G  17% /mnt/suse
/dev/sda1     vfat    241M  152M   90M  63% /media/usbdisk

You can use the du command to determine which files or directories need to be deleted — or at least trimmed. A simple du will print usage for the present working directory and its subdirectories, along with the size of each directory.

If you want the size of an particular directory, specify it with du directoryname. For instance, du -h /home/bodhi/podcasts will print the size of the podcasts directory in a more readable format than the kilobytes used by default. The -c option prints the grand total size of the directory at the end. The -a option also displays the file names along with directories and can be of use when you want to see a list of files in a particular directory. The -s option will display a summary, without showing all of the subdirectories.

Running du -ch | grep total prints just one line with the total size of the directory. If there’s a particular type of file that you would like to be excluded while calculating a directory’s usage, specify it with the --exclude=type option. Here we’ll check the disk usage of the current directory, and display all file names with their disk usage, and then sort them numerically using the sort utility:

$ du -ah | sort -n
4.2M    ./eweek.10.28.05.mp3
4.5M    ./LQ-Podcast-101105.mp3
4.8M    ./LQ-Podcast-110905.mp3
19M     ./LQRadio-Episode3.mp3
20M     ./LQRadio-Searls.mp3
36M     ./LQRadio-HiserAndAdelstein.mp3
197M    .
Categorized under: css, graphics, html, images, programming

Background image generator – BgPatterns.com

After Ian posted this on his blog I thougth I would follow suit. (He always seems to find the cool stuff.)

This very nifty site allows you to create tiled background images for use wherever you may need them. At first I thought “yuck, I stopped using backgrounds long ago”. But after playing with rotation, colors, and opacity I found that a pretty nice tiled background can be useful when applied right.

It is very difficult to do a good job on tiled backgrounds, but this site makes it easy.
www.BgPatterns.com

Categorized under: Databases, MySQL, OS, Ubuntu, programming

MySQL not creating mysql.sock and broken on Hardy Heron

Recently I started receiving errors when I tried to connect to MySQL using command line or PHPMyAdmin. In command line I would get “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)”, and with PHPMyAdmin I would get “#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)”.

The system in question is my Dell Inspiron 1720 running Hardy Heron Ubuntu. I knew of a few changes to my system, but none of them seemed to have caused the problem. So I hunted for a few days trying to figure it out. I performed multiple searches on the net, and each led me to a dead end. Many said, “Set this … in your php.ini” or “Set that … in your my.cnf”, and some even said Apache was to blame. However, I found the solution to be very simple.

MySQL was expecting the mysql.sock to be located in ‘/tmp/mysql.sock’. However, for some reason it had moved or the symbolic link to it’s actual location was deleted by some update or install I did recently.

I fixed the problem by adding a symbolic link to the actual home of mysqld.sock, which was /var/run/mysqld/mysqld.sock. Here is how I created the symbolic link: (at the command line)

sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

sudo puts us in super user mode, “ln -s” creates a symbolic link followed by the target the links sould point to and last by the location of the link.

Edited on Sep. 26th with update below:

The fix above did not work as a permanent fix. I found that whenever I rebooted the OS it forced me to recreate the symbolic link. MySQL was failing to recreate the symbolic link on it’s own. To permanently fix the issue I needed to add the creation of the symbolic link to my SESSION startup. Here is how I did that:

By going to the System->Preferences->Sessions to edit the Startup Programs. I added an item that automatically issues the command above, but without the “sudo”.

Mission accomplished…permanently.

RSSSubscribe to my feed now.

About Me

GeekyBoy.com