- For clean log, shell script already exist in path-to-magento/shell directory:

    <pre>php log.php 
    Usage:  php -f log.php -- [options]
            php -f log.php -- clean --days 1
    
      clean             Clean Logs
      --days <days>     Save log, days. (Minimum 1 day, if defined - ignoring system value)
      status            Display statistics per log tables
      help              This help</pre>


 - For clean cache, following methods will help you to make a shell script:

    <pre>
    // Clean js and css
    Mage::getModel('core/design_package')->cleanMergedJsCss();
    Mage::dispatchEvent('clean_media_cache_after');

    // product image
    Mage::getModel('catalog/product_image')->clearCache();
    Mage::dispatchEvent('clean_catalog_images_cache_after');

    // Get cache types
    Mage::app()->getCacheInstance()->getTypes()

    // Clean specific tags
    Mage::app()->cleanCache($tags);

    // dispatch event if you flush all cache tags
    Mage::app()->cleanCache($alltags);
    Mage::dispatchEvent('adminhtml_cache_flush_system');
    </pre>