Friday, 30 November 2012

Create a diary for your daily workflow

You can modify your ~./bash_history file so it doens't store duplicates and stores more lines than the default (only 1000):

export HISTCONTROL=erasedumps
export HISTSIZE=100000
shopt -s histappend
view raw diary1.sh hosted with ❤ by GitHub


However, sometimes you want to go back to your history file and see what commands you issued on a particular day .... one solution is to make a periodic backup with a timestamp using cron.

First, make a directory to put your files in, and make a script which is going to do the work:

cd
touch backup_history.sh
mkdir history
view raw diary2.sh hosted with ❤ by GitHub


Open the shell script and copy the following inside

nano backup_history.sh
DATE=$(date +"%Y%m%d%H%M")
cp ~/.bash_history ~/history/$DATE.log
view raw diary3.sh hosted with ❤ by GitHub


close, then in the terminal issue

sudo nano /etc/crontab
#and copy the following
@hourly ~/./backup_history.sh
view raw cron.sh hosted with ❤ by GitHub

admittedly hourly is a little excessive - go here is you are unfamiliar with cron scheduling definitions and modify as you see fit

No comments: