#!/usr/bin/perl -w use strict; use Term::ReadLine; use POSIX qw(strftime); my $username = getlogin(); my %cfg = ( shell => '/bin/bash', dateformat => '[%Y%m%d-%H%M%S] ', logpath => '/tmp/sessionlogs/', logname => "$username.session.log", ); my @prohibited_cmds = ( 'mc', '/usr/bin/mc', ); open LOGFILE, ">>$cfg{logpath}$cfg{logname}" or die "Cannot open log file!"; print LOGFILE "-----------------------------------\n"; print LOGFILE strftime $cfg{dateformat}, localtime; print LOGFILE "Session started for $username.\n"; my $term = new Term::ReadLine 'Shellwrapper'; $SIG{'INT'} = 'IGNORE'; while (defined ($_ = $term->readline('SH+log> '))) { if ((/^\s*quit\s*$/) or (/^\s*exit\s*$/)) { print LOGFILE strftime $cfg{dateformat}, localtime; print LOGFILE "$_\n"; last; } # first log timestamp and commandline print LOGFILE strftime $cfg{dateformat}, localtime; print LOGFILE "$_\n"; # then execute system "$cfg{shell} -c '$_'"; print "\n"; } print LOGFILE strftime $cfg{dateformat}, localtime; print LOGFILE "Session terminated for $username.\n"; close LOGFILE; #### ----------------------------------- [20120516-222413] Session started for testuser17. [20120516-222419] test shellexample [20120516-222420] exit [20120516-222420] Session terminated for testuser17.