Archive for the ‘scripts’ Category

Domain redirection using PHP script

June 18, 2008

If you want to redirect a domain to some other url, you can use the PHP script below.

index.php
—————————————-
<?php
header(”Location: http://destination-domain.com/where-you-want-to-redirect/index.html”);
exit();
?>
—————————————-

So, when you take http://your-domain.com or http://your-domain.com/index.php it will be redirected to “http://destination-domain.com/where-you-want-to-redirect/index.html”.

Find command

September 24, 2007

find . -path ‘./media’ -prune -o -print
Find all files in this directory (.) -prune (ignore) the proceding path of
‘./media’ Then if no match print (prune or print)
Linux Find Modified with certain time period with excluded directory
find . -path ‘./media’ -prune -o -mtime -30 -print
Find all files in this directory (.)
-prune (ignore) the proceding path of ‘./media’
Modified within the last 30 days print the results.
find . | xargs grep ’string’

Find files with certain extensions

September 24, 2007

#Searches the current directory and deeper for several extensions. In this example both files mathing ‘php’, ‘html’ and ‘tpl’ match the search.
find ./ -regex “.*\(php\|html\|tpl\)$”

Delete empty directories (UNIX)

September 24, 2007

// Shell command to delete empty directories. May have to run several times to get everything.
find . -type d -empty | xargs rmdir -

Making MySQL executable scripts

September 24, 2007

#! /usr/bin/env bash

# execute some bash scripting commands here

mysql mydatabase <<SQL_ENTRY_TAG_1
SELECT *
FROM mytable
WHERE somecondition=’somevalue’;
SQL_ENTRY_TAG_1

Load average finder

September 24, 2007

#!/bin/bash
loadavg=`uptime | awk ‘{print $10}’`
# bash doesn’t understand floating point
# so convert the number to an interger
thisloadavg=`echo $loadavg|awk -F \. ‘{print $1}’`
if [ "$thisloadavg" -ge "2" ]; then
echo “Busy – Load Average $loadavg ($thisloadavg) “
top -bn 1
else
echo “Okay – Load Average $loadavg ($thisloadavg) “
fi