Timesheet Prompt

July 31st, 2009

Warning: This post is 15 years old. Some of this information may be out of date.

At work we keep track of work and time by using a web-based timesheet system. This requires employees to update their online timesheet on a daily basis.

Some of the Linux users use a text file to update the timesheet (via a python script written by a colleague) but there still remains the problem of remembering to update the text file when completing a job.

I have written a small bash script that uses Zenity to prompt me for information and then write it to my log file.

Here is the script:

    export DISPLAY=:0.0
    THETIME=`date +%H:%M`
    THEDATE=`date +%Y-%m-%d`
    LOG='~/bin/logs/'`date +%Y`'/'`date +%b`'/'`date +%d`'.txt'
    LOGFILE=`echo $LOG | tr "[:upper:]" "[:lower:]"`
    
    TEXT=`zenity --entry  --title="Timesheet Update" --text="$THETIME: What are you working on?" --entry-text ""`
    
    # check if logfile exists and if not, create it
    
    if [ ! -f $LOGFILE ]; then
        touch $LOGFILE;
        echo "$THEDATE:" >> $LOGFILE;
    fi
    
    case $? in
    
                 0)
            echo "$THETIME - $TEXT" >> $LOGFILE;;
                 1)
                        echo "Nothing Added.";;
                -1)
                        echo "Nothing Added.";;
        esac

I set up a cron to run this script every 30 minutes during working hours.

At the end of the day I open the timesheet file, format it and send it to the python script to update my log. Simple.