Piping the "script" command through the logger command.

Discussion in 'Programming/Scripts' started by woodson2, Sep 12, 2013.

  1. woodson2

    woodson2 New Member

    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
     

Share This Page