Magento: stand alone php script that uses native magento functions

The Mage_Shell_Abstract class initializes the Mage app on object creation. By extending the Mage_Shell_Abstract in the the MageRoot/shell/abstract.php, you can write stand alone scripts that uses all the native Magento functions such as getting data by using the getModel function.

As an example, you can create a file MageRoot/shell/test.php

<?php
require_once 'abstract.php';
class Mage_Shell_Test extends Mage_Shell_Abstract
{
public function run()
{
$this->catalogProduct();
$this->loadCustomer();
}
public function loadCustomer()
{
$customer=Mage::getModel('customer/customer')->load(2);
//name and email is a field in the customer_entity table, getName() and getData are magic function you can use to get any field values of the model
echo $customer->getName()."\n";
echo $customer->getData('email')."\n";
}
public function catalogProduct()
{
$_product = Mage::getModel('catalog/product')->load(166);
echo $_product->getData('name')."\n";
echo $_product->getFormatedPrice()."\n";
}
}
$shell = new Mage_Shell_Test();
$shell->run();

And run the script by cd to MageRoot/shell/ and issue this command or the script can also be triggered by a cron job.