How do I know if I installed latest version? I am trying to create a cron script which uses Drush, and that does the following (using pseudo-code).

if([My Drupal core version] &lt; [The last core version]) {
    [Backup DB]
    [Put the site into maintenance mode]
    [Upgrade core]
    [Remove the site from maintenance mode]
}


I don't know, how to implement [My Drupal core version] &lt; [The last core version]. 

How do I check if the site is using the latest version of Drupal?
You could try drush pm-updatestatus drupal and see if you get any results.