#!/bin/bash #.Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y #.YT 3 2 0 0 3 3 1 / / / #.H!a!0:linux//time/cron/THIS!0.!c # # copyright : (C) 2012 by Thomas Bruecker =: tbrue # email : public0x05bf@bluewin.ch # # tbrue 14jun2012 # # time/cron THIS : cron-functions # +++++++++++++++++++++++++++++++ # # MyHash("linux//time/cron/THIS") = 0x0XYZH # # * for every function: # * if returned result is not commented, the function returns 0 on no-error. SCRIPTS=root/bin . /$SCRIPTS/time/THIS cron_2Time() # $1 : execution-time as "canonical time0" (e.g. "14jun2012-10h36m02"), # checks and converts the execution-time time to a 'cron-tab-time'. { local Result Time Time=$( time_canonicalTime0_2Time "$1" ) Result=$? if [ 0 != $Result ]; then # error in time-command. return $Result fi # else Time="\"$( time_2cronTime "$Time" )\"" Result=$? if [ 0 != $Result ]; then # error in time-command. return $Result fi # else echo $Time return # return result of previous # command. } cron_Add() # $1 : execution-time as "canonical time0" (e.g. "14jun2012-10h36m02"), # $2 : command to execute; # writes an entry according to the above specifications in the cron-tab of # the current user and reloads cron. { local Result cron_add "$1" "$2" Result=$? if [ 0 != $Result ]; then # error in add-command. return $Result fi # else cron_reload return # return result of previous # command. } cron_AddJob() # $1 : execution-time as "canonical time0" (e.g. "14jun2012-10h36m02"), # $2 : (base)name of job-command to execute; # writes an entry according to the above specifications in the cron-tab of # the current user and reloads cron. { local Result cron_Add "$1" "/root/bin/scripts/time/cron/jobs/${2}" return # return result of previous # command. } cron_add() # $1 : execution-time as "canonical time0" (e.g. "14jun2012-10h36m02"), # $2 : command to execute; # writes an entry according to the above specifications in the cron-tab of # the current user. { local Command CronTablesPath Result Time User Command="$2" CronTablesPath="/var/spool/cron/" Time=$( cron_2Time "$1" ) Result=$? if [ 0 != $Result ]; then # error in time-command. return $Result fi # else User=$( /usr/bin/whoami ) Result=$? if [ 0 != $Result ]; then # error in "whoami"-command. return $Result fi # else echo -n $Time | sed 's/\"//g' >> "$CronTablesPath$User" echo " $Command" >> "$CronTablesPath$User" return # return result of previous # command. } cron_reload() # reloads the cron-tabs to make them valid. { /sbin/service crond restart return # return result of previous # command. }