Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

Search and Delete Files less than 1 hour old with vbscript

Ran into a situation where temporary created files were filling the drives of a Windows 2003 server. So I turned to vbscript and creating a scheduled task to keep the space issue at bay. Here is the script.

' VBscript to delete files older than 1 hour
' directory to delete
' cleanoldfiles.vbs

' change dir variable to directory to target files
sdir="d:\my dir"
dim dt, fso, odir, f
dt=now
set fso=createobject("scripting.filesystemobject")
if fso.folderexists(sdir) then
set odir=fso.getfolder(sdir)
for each f in odir.files
'"n" for minutes, "h" for hours etc, also change "zip" to file extension to look for
if (strcomp(fso.getextensionname(f.name),"zip",1)=0) and (datediff("n",f.datelastmodified,dt)>30) then
f.delete true 'forced
end if
next
set odir=nothing
else
wscript.echo "directory: " & sdir & " not found." & vbcrlf & "operation aborted."
end if
set fso=nothing

The script is pretty simple and can be changed to handles hours and minutes by changing the h and N variables. For under 1 hour times you need to make sure h = 0, this variable is set right after the file extention. Comments are listed in the code example above.

Hope this little script can be as much use for you as it is me.

Quick and Easy Backup Batch File Windows

Backups are an evil necessity and as with most geek admins we tend to forget to do it. We think of grand schemes and how we can do it better. Well I am still thinking of those grad schemes but in the meantime I use a simple command file to backup file off one drive to another that will only copy newer files. What is so nice with this is I don’t have to have a backup program to retrieve the data, but the drawback is that it uses alot of space. Running it the first time will back them all up but future runs are fast.

The batch file uses xcopy as the start with several switches, displays it in colored backgrounds and writes a logfile when it is done. Here is the simple backup.

@ ECHO OFF
rem
rem    FILE NAME:  myback.cmd
rem
rem    UPDATED:    May 10, 2011
rem
rem    Purpose:    Backup NAS files to another drive
rem
rem
rem    =====================================================================
rem
rem
cls
color 1e
@ECHO.
@ECHO.
@ECHO.
@ECHO.
@ECHO  Press Enter Key to run the program.
@ECHO  Key Ctrl+C to abort, now or anytime later.
@ECHO.
@ECHO.
@ECHO  Backup running...please wait.
@ECHO.
@ECHO.
@ECHO.
@ECHO.
@ECHO.
@ECHO.
COLOR 1B
@ECHO Copying files with more recent dates...
XCOPY "z:\documents\*.*" "i:\backup\documents\*.*" /d /E /R /f /H /Y
XCOPY "z:\downloads\*.*" "i:\backup\downloads\*.*" /d /E /R /f /H /Y
@ECHO.
@ECHO.
@ECHO.
@ECHO.
@ECHO.
Echo. >i:\back_doc.txt
Echo. >>i:\back_doc.txt
Echo. 	The Following Files Have Been Backed Up >>i:\back_doc.txt
Echo. 	--------------------------------------- >>i:\back_doc.txt
Echo. >>i:\back_doc.txt
Echo. >>i:\back_doc.txt
DIR i:\backup\*.* /-B /-S /on >>i:\back_doc.txt
tree i:\backup /A /F >>i:\back_doc.txt
REM
REM
CLS
color e9
@ECHO.
@ECHO.
@ECHO.
@ECHO.
ECHO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ECHO !!                                                         !!
ECHO !!             BACKUP PROCEDURE HAS COMPLETED.             !!
ECHO !!                                                         !!
ECHO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ECHO.
@ECHO.
@ECHO.
:end

That’s all there is to it. To add more directories just copy one of the lines and change the directory names. For further automation use Windows Scheduled Tasks to add the command to run behind the scenes. You can do this the GUI way or command line. My preference is at the command line.

This example shows to run it weekly

schtasks /Create /SC WEEKLY /TN Backup /ST 03:00 /TR c:\scripts\myback.cmd

Now we are set. For the initial backup you can double click on the command file and watch it run. Then the scheduled task will run much faster.

 

 

WordPress on XAMPP

Recently after installing XAMPP on my system I wanted to start developing WordPress themes. The best way to accomplish this with Dreamweaver CS5 is to have a local install so that editing the files locally was easy. Looking around I found this is really an easy task to accomplish.

First download the latest from WordPress. Once the download is completed unzip the files to C:\xampp\htdocs, this will create a wordpress directory.

Next step is to create an empty database. To accomplish this task open a browser and type http://localhost/phpmyadmin and you will be connected to the phpMyADmin service. In the create database section type wordpress and click create.

wordp1

Exit phpMyAdmin and open Windows Explorer and open C:\xampp\htdocs\wordpress\wp-config-sample.php with a text editor of your choice.  Find the following lines and change the database name to wordpress and your username and password for XAMPP, which by default is root with no password.

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */
define(‘DB_USER’, ‘root’);

/** MySQL database password */
define(‘DB_PASSWORD’, ”);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Save the file as wp-config.php.

Open your Internet browser and type in http://localhost/wordpress/wp-admin/install.php and everything from there should run smoothly to complete the installation.

Quick and Easy Apache/PHP/MySQL on Windows

While working on a website for a customer came upon a connectivity issue while working on a laptop getting to the Linux server to test the code. I thought about installing Apache / MySQL / PHP all locally on the laptop and setup a testing server, when I stumbled on XAMPP.

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use – just download, extract and start. The current version is 1.7.4 and contains: Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql.

Installation is pretty simple. Double click on xampp-win32-1.7.4-VC6-installer.exe to start the process. Click OK to select the Language (English). Click Next on the Welcome screen.

xampp1

Next is the location of where XAMPP root will be on the system. The default is c:\xampp which will work in most cases, but if you have a separate drive you can change the location. When you are satisfied click next to continue.

 

xampp2

This will bring up the XAMPP Options screen. The service section has the option to start Apache, MySQL and Filezilla as a service at startup time. For our purpose I have checked the boxes for Apache and MySQL to start. If you choose not to you can always use the XAMPP control panel to start / stop the services. Once you are satisfied click Install. The installation will take a few minutes to complete, just sit back and relax and click finish when you are prompted.

xampp3

You now have a running web server with a database to start working with on your system.

Remotely Posting Blogs WordPress 3.1

Recently I found the need to be able to use a Weblog client to connect to the sites and post content. There are several clients available to handle this task for Linux, MacOSX and Windows. As a matter of fact this post was created using GScribble (Linux).

Installing the Weblog Client and trying to connect immediately will not work. You have to enable “Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.” in your WordPress Dashboard.

Login to the WordPress Dashboard for your Blog and click Settings -> writing and check “Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.” Click Save Settings and you are ready to receive posts.

Now you are ready to install a Weblog Client. For a list of whats available goto Weblog Clients Since I am running Fedora 14 I chose GScribble.

To install it just open a terminal and type $ sudo yum -y install gscribble and you are done!
Next step is to open GScribble and set the preferences to connect to the blog. Just enter in Type (WordPress), URL, Username and password, click OK and you will be connected.

The interface is clean and simple and fairly self explainable. The program allows you some level of formatting and ability to add categories. One issue is that it does not support image uploading and embedding in the posts.

 

That’s all for this quick post. Look for future posts on Windows Clients and more advanced information on Weblog clients and WordPress.

Install Kdenlive on Fedora 14/15 64 bit

Recently I rebuilt a system to run Fedora 14. One of the many jobs I plan to use it for is for video editing and one of best Linux editors in development is Kdenlive. According to the site, Kdenlive is an intuitive and powerful multi-track video editor, including most recent video technologies. So let’s move on to the install.

Part of the issue with installing Kdenlive is that it is not in the repository but can be found in the rpmfusion free and non-free repositories. So first step is to add the repositories.

$ su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'

Now that the repository is loaded you need to run the install. If you run the command as you would normally it will fail getting libmlt. To resolve this issue you need to temporarily enable the rpmfsion-free-updates-testing repository and install Kdenlive. At the time of this posting 0.8.1 is available.

$ yum --enablerepo=rpmfusion-free-updates-testing -y install kdenlive

Once the command is completed Kdenlive is available. Refer back to the blog for more postings on the adventures of using Kdenlive or feel free to explore yourself and use the great documentation on Kdenlive’s website.

Note: With Fedora 15 you may have a crash caused by MLT. If you experience the crash you will need to downgrade MLT. You can do this by running the command.

$ sudo yum –downgrade mlt

Kdenlive Interface

Switch to our mobile site