Delete/create nodes programmatically I created a custom module that uses the Taleo Web API to get data from the external Taleo database and make nodes from this data. This works great.

But now I want to run this update script every night... The script works great whem I logged in into Drupal.

What would be the safest way to allow deleting and adding nodes programmatically when logged out?

function taleo_menu() {
  $items['taleo-update'] = array(
    'title' =&gt; 'Taleo Update page',
    'description' =&gt; 'Taleo Update page',
    'page callback' =&gt; '_taleo_update',
    'access arguments' =&gt; array('view content'),
        'type' =&gt; MENU_NORMAL_ITEM,
  );    
    return $items;
}

function _taleo_insert($jobs) {
    foreach ($jobs as $job_object) {

        $node = new stdClass();
        $node-&gt;type = 'job';
        $node-&gt;title    = $job_object-&gt;title;
        $node-&gt;language = LANGUAGE_NONE;

        node_object_prepare($node);
        $node = node_submit($node); // Prepare node for a submit
        node_save($node); // After this call we'll get a nid
    }

    drupal_set_message(t('Added %count jobs.', array('%count' =&gt; count($jobs))));   
    return array();
}
If you are looking for the safest way, I would say your current approach is not how most of us get things done in Drupal. 

Basically, you can make use of a hook that wakes up your module, check last run's status and if suitable, start its next run. 

Check out hook_cron. You can check last run status easily from a variable_get (you need to set the value first using variable_set). Cron runs anonymously regardless of a specific page call. Even if the cron runs frequently, you can use some condition to check last run timestamp and compare it to current system time. If it has exceeded the interval (1 day), you can now run the "create nodes" function. 

If nodes are saved correctly, you will see a $node->nid set. use that as a condition and if all given jobs are done, you can set the last run variable to the current time.