28 Feb 2011

Search and update Google Base with PHP


Use PHP to process and integrate data from Google Base with a custom Web application
Google Base allows users to store any type of content online in Google's version of a massive online database. Web application developers are able to access and search this content through the Google Base Data API. This article introduces the Google Base Data API and demonstrates it in the context of a PHP application, explaining how to use SimpleXML and the Zend_Gdata module to search, retrieve, add, and edit different types of data on Google Base.
http://www.ibm.com/developerworks/library/x-gbase/

Delete directories older than a set number of days


Find subdirectories under a path and delete any older than a set number of days.
find /path/* -type d -ctime +6 | xargs rm -r

Bash script lftp with lock file


Bash script to upload a directory to a remote ftp site.

Uses the built in mirror function of the lftp ftp client.

A lock file is created so script so two instances of the script cannot conflict with each other.
#!/usr/bin/bash
LOCKFILE=/tmp/ftp_mirror.lock

if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
   exit # already running
fi

HOST="ftphost"
USER="username"
PASS="password"

LCD="localpath"
RCD="remotepath"

# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}

# upload files
lftp -c "set ftp:list-options -a;
open ftp://$USER:$PASS@$HOST;
lcd $LCD;
cd $RCD;
mirror --reverse"

rm -f ${LOCKFILE}