Register
It is currently Tue Jul 22, 2014 9:24 am

Piping the "script" command through the logger command.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu Sep 12, 2013 11:00 am   

Joined: Mon Apr 27, 2009 2:24 pm
Posts: 10
I use the snippet below in /etc/profile on RHEL Linux to capture command line logging and it all works well and good.

Now I'd like to pipe the same output from script through the logger command so it all gets logged to syslog.

The only additional code I've added is in bold below (| bin/logger).

This works as expected sans one issue, albeit a major one. My terminal session is blank as if nothing is being typed, however if I type commands I can see them being logged and if I type exit my session closes. I tried a nohup and & to see if that would help but it does not. I'm wondering why I can no longer see anything on my tty.

This is what my putty session looks like. So I have a fully functional session but I can't see any output.
[user@test1 ~]$ ssh cxxx
user@test1's password:
Last login: Thu Sep 12 09:56:01 2013 from 10.x.x.x



Code:
if [ -z $PS1 ]
  then
    echo "" > /dev/null
  else
    DATE="/bin/date"  SCRIPT="/usr/bin/script"
    LOGBASE="/log/cmdline_logs"
       if [ -d "${LOGBASE}" ]; then
           TIMESTAMP="$( ${DATE} +%Y%m%d%H%M%S )"
           LOGFILE="${LOGBASE}/${HOSTNAME}_${USER}_${TIMESTAMP}"
           umask 077
           [[ "${SHELL}" = "/bin/bash" && -e "${HOME}/.bash_profile" ]] && . ${HOME}/.bash_profile
           ${SCRIPT} -f -q ${LOGFILE}.log | /bin/logger
           [[ "${SHELL}" = "/bin/bash" && -e "${HOME}/.bash_logout" ]] && . ${HOME}/.bash_logout
           exit
       fi
 
fi


Top
 Profile  
 PostPosted: Wed Sep 18, 2013 2:33 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
Instead of piping it directly to the logger, look at using the "tee" command, that way you can see it on your screen and send it to the logger as well.


Top
 Profile WWW  
 PostPosted: Wed Sep 18, 2013 5:12 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
hi crouse,

unfortunately that doesn't work either.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP