Bootstrapping Drupal from the command line
Don't even try this. Use drush, it is meant for this type of things precisely.

The drush php-script command will allow you to run any PHP script in the context of Drupal, but I would recommend writing those as a proper command inside a custom module.