Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like an easy to read log of when a particular application was started. The log needs to include a timestamp and to record the actions I took, for example when I launched a browser or launched a game.

share|improve this question

4 Answers 4

up vote 1 down vote accepted

Bash records history of all the commands you run, and you can have it record a timestamp as well - see http://larsmichelsen.com/open-source/bash-timestamp-in-bash-history/ for more.

But the bash history doesn't hang around forever, and it still only records things you run from the command line.

share|improve this answer

Your own proposal is not bad at all. Such a script could be something of the form

#!/bin/bash

# Get the program you wish to launch from arguments
PROGNAME="$1"
# Shift script arguments to use the remaining ones later
shift

# Check that a PROGNAME was provided
if [ -z "$PROGNAME" ]; then
   echo "Usage: $0 <program> [program options]"
   exit 1
fi

# Log in your home directory, one directory per program
LOGDIR="$HOME/logs/$PROGNAME"

# Create log directory if it doesn't exist yet
if [ ! -d "$LOGDIR" ]; then
   mkdir -p "$LOGDIR"
fi

# Get the date now
DATE=$(date +'%Y%m%d%H%M%S')

# Start program with it's options and log into the logdir
eval "$PROGNAME" $@ >"${LOGDIR}/${PROGNAME}_${DATE}.log" 2>"${LOGDIR}/${PROGNAME}_${DATE}.err"

Now you could very well edit the entries in your desktop launch menu to use your wrapper everytime you launch a certain program.

Another option would be to use sudo, which logs to auth.log automatically, but use it in such a way that it doesn't launch the programs as root, that is:

sudo -u $USER firefox

which will launch firefox as yourself, using sudo.

For example:

$ sudo -u $USER ksnapshot
# I kill the program
$ tail -1 /var/log/auth.log
   Dec 28 08:20:07 jonah sudo:  raphink : TTY=pts/1 ; PWD=/home/raphink ; USER=raphink ; COMMAND=/usr/bin/ksnapshot
share|improve this answer

One possibility would be to write a small bash script of the form

$ myLogging firefox

that would log the time that, in this example, firefox started and then simply start firefox.

This would require, however, that I do all my actions, such as starting an application, from the command line. Also, what if I wanted to start firefox with some arguments of its own?

share|improve this answer

I don't know whether 'snoopy' is available for Ubuntu, but on Debian it logs every command you've run to /var/log/auth.log .

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.