Wednesday, March 13, 2013

CRON: simple kernel pull/build with email notification

The post below shows you how to setup up a simple crontab to do simple tasks with an email notification..

1) depending on your distro you might already have cronwrap intsalled or in the repo(s)
if not download and install

cd Downloads
tar xvfz  cronwrap*.tar.gz
cd cron*
python install
which cronwrap
exit ; cd

2) /etc/anacrontab is the main config file as well as /etc/crontab for "root" jobs in the system.

this exercise does not deal with these files, but they can be modified for added root tasks for the system for regular tasks.

3) create/start your own crontab under your username located in /var/spool/cron. the simple task of resetting the kernel and pulling.

crontab -e
enter the entries for the times you want etc.. then save and exit.
30 21 * * * /usr/bin/cronwrap -c "/home/kernel./pull_script" -e -v

NOTE: below is my simple script I used for this example

<----- copy/paste------->

# my cheesy script to pull the kernel 

for dir in /home/kernel/3.0*  
cd /home/kernel/3.0 ; git reset --hard origin ;
git checkout master ; git pull ; 
git checkout Mattock ; git reset --hard origin ; make 

Mail info:
I used cronwrap since it makes sending info to myself much easier, and supplies good info in the email on how everything went(not just when things crap out)
crond does send emails but only if the scripts fails. to add this option add:
MAILTO= at the top of your crontab -e

4) create another task as "root" to complete the job

crontab -e
add the root commands that need to fire off after the pull and build go through.
30 22 * * * /usr/bin/cronwrap -c "cd /home/kernel/3.0 ; make modules_install ; make install" -e -v

probably should of created another script, but wanted to show you don't need to make scripts to do this..

5) check the logs,(/var/log/cron) and wait for the email.. hopefully everything goes good for whatever commands you use!

the first script for pulling went good, but then when it came for the root crontab I hit a strange error:

/sbin/installkernel: line 82: new-kernel-pkg: command not found
/sbin/installkernel: line 86: new-kernel-pkg: command not found
make[1]: *** [install] Error 127
make: *** [install] Error 2

quick fix is to edit this file at 82 and 86 by adding the full path to the programs

and there you have it.. a simple cron example of pulling and resetting the kernel, then building and installing everyday between 8-9:30pm without having to do anything..because we all know how hard entering commands in a terminal can be!

No comments:

Post a Comment