FedoraForum.org - Fedora Support Forums and Community
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2005
    Age
    43
    Posts
    523

    get wall messages via email?

    Ok I'm always learning something here and there and came across an interesting command, "wall".

    While looking at what apcupsd would do when loss of power I see that it calls "wall" to send a message. I could add code to /etc/apcupsd/apccontrol to also email me but now I'm not going to rest till I get "wall" to also send an email to me. Since anything sent to "wall" on that server I would want to know.

    I tried a bit of googling already but I'm not finding much more than what I already know about it.

    If I could just figure out how to run a script from messages sent to wall that would be nice.

    I guess I could alway wrap the real wall with a script I put together but that would be last resort. I'd really like to know if there is a clean way.

    I'd also like wall to pop up a message on my xfce desktop also.

    Reading this now

    http://tilde.club/~phooky/logging_wall.html

    Hoping to find the answer

    thought of idea while reading ssh localhost maybe a way... continuing reading...

    ahh they where unsuccessful but my ssh loop may work give me a bit and I may have solved a long mistery.

    oooh progress

    so I have screen installed and I setup passwordless ssh
    I start a screen and "ssh localhost | tee ssh_loop.txt" detach from screen via ctrl+a d and wala I can log wall messages. I'll see if I can figure out how to start this automatically but at least I am further along then phooky got.
    Last edited by Jeff Sadowski; 12th October 2017 at 08:20 PM.

  2. #2
    Join Date
    Jun 2005
    Age
    43
    Posts
    523

    Re: get wall messages via email?

    I finished writing my wall watching script. It has a small bug that I was not able to see
    I noted in my code where there is a possibility of my script chomping the file before it is read next

    Code:
    #!/bin/bash
    
    # filename: wall_logger.sh
    # to start the logger type "./wall_logger.sh"
    # it should only start one instance so you should be able to attempt
    # starting it multiple times.
    #
    # to stop "./wall_logger.sh stop"
    #
    # it will loop every second waiting for new wall messages
    # and if there are new messages they will be displayed via
    # notify-send and be sent to an email if email is setup properly.
    #
    # setting up email you must create a ~/.wall_loggerrc file that has something like
    # TO=me@somplace.com
    # and you must setup mutt to properly send email via ~/.muttrc
    # my ~/.muttrc looks similar to
    #
    # set from = "me@gmail.com"
    # set realname = "My Name"
    # set smtp_url = "smtp://me@gmail.com@smtp.gmail.com:587/"
    # set smtp_pass = "my 16 character app password because I use 2 factor authentication"
    # set imap_user = "me@gmail.com"
    # set imap_pass = "my 16 character app password because I use 2 factor authentication"
    # set folder = "imaps://imap.gmail.com:993"
    # set spoolfile = "+INBOX"
    # set postponed = "+[Gmail]/Drafts"
    # set header_cache = "~/.mutt/cache/headers"
    # set message_cachedir = "~/.mutt/cache/bodies"
    # set certificate_file = "~/.mutt/certificates"
    # set mail_check = 30
    # set move = no
    # set imap_keepalive = 900
    # set sort = threads
    # set editor = "nano"
    
    new_msgs()
    {
     while [ 1 ];do
      sleep 1
     ##
     ## chance of loss between the next two active lines
     ##
      MSGS=$(cat $1)
      echo -n > $1
      if [ "${MSGS}" != "" ];then
       export DISPLAY=:0
       notify-send "$(echo -e "${MSGS}")"
       if [ -f ~/.wall_loggerrc ] && [ -f ~/.muttrc ];then
        TO=""
        . ~/.wall_loggerrc
        if [ "${TO}" != "" ];then
         echo -n
         echo -e "${MSGS}" | mutt -s "wall messages from $(hostname) at $(date)" ${TO}
        fi
       fi
      fi
     done
    }
    
    start()
    {
     LOGFILE=$(ps -fC bash|grep "bash -c ssh localhost | tee /tmp/wall[_]"|head -n 1|sed 's/.* \(\/tmp\/wall_[^ ]*\).*/\1/')
     if [ "${LOGFILE}" = "" ];then
       LOG_FILE=/tmp/wall_$(date "+%s").log
       screen -d -m bash -c "ssh localhost | tee ${LOG_FILE}"
       while [ ! -f ${LOG_FILE} ];do sleep 1;done
       echo -n > ${LOG_FILE}
       new_msgs ${LOG_FILE} 2>/dev/null &
     fi
    }
    
    case $1 in
     stop)
      pid=$(ps -fC bash|grep "bash -c ssh localhost | tee /tmp/wall[_]"|awk '{print $2}')
      if [ "$pid" != "" ];then kill -9 ${pid};fi
      pid=$(ps -ef|grep $(basename $0)|awk '{print $2}')
      if [ "$pid" != "" ];then kill -9 ${pid};fi
      rm -rf /tmp/wall_*
      ;;
      *)
       start &
      ;;
    esac
    Last edited by Jeff Sadowski; 13th October 2017 at 10:59 PM.

  3. #3
    Join Date
    Jun 2005
    Age
    43
    Posts
    523

    Re: get wall messages via email?

    Updated functions to guarantee no loss of messages

    Code:
    new_msgs()
    {
     while [ 1 ];do
      sleep 1
     ##
     ## chance of duplicated message in the next 4 active lines
     ##
      echo -n > $2
      MSGS=$(cat $1)
      echo -n > $1
      MSGS="${MSGS}$(cat $2)"
      if [ "${MSGS}" != "" ];then
       export DISPLAY=:0
       notify-send "$(echo -e "${MSGS}")"
       if [ -f ~/.wall_loggerrc ] && [ -f ~/.muttrc ];then
        TO=""
        . ~/.wall_loggerrc
        if [ "${TO}" != "" ];then
         echo -n
         echo -e "${MSGS}" | mutt -s "wall messages from $(hostname) at $(date)" ${TO}
        fi
       fi
      fi
     done
    }
    
    start()
    {
     LOGFILE=$(ps -fC bash|grep "bash -c ssh localhost | tee /tmp/wall[_]"|head -n 1|sed 's/.* \(\/tmp\/wall_[^ ]*\).*/\1/')
     if [ "${LOGFILE}" = "" ];then
       DATE=$(date "+%s")
       LOG_FILE=/tmp/wall_${DATE}.log
       CHK_FILE=/tmp/chck_${DATE}.log
       screen -d -m bash -c "ssh localhost | tee ${LOG_FILE}"
       screen -d -m bash -c "ssh localhost | tee ${CHK_FILE}"
       while [ ! -f ${LOG_FILE} ];do sleep 1;done
       echo -n > ${LOG_FILE}
       new_msgs ${LOG_FILE} ${CHK_FILE} 2>/dev/null &
     fi
    }

Similar Threads

  1. missing wall messages from apcupsd
    By sliptrap in forum Using Fedora
    Replies: 1
    Last Post: 15th January 2013, 11:51 AM
  2. Email messages are put in receiver's Spam folders
    By alecswan in forum Servers & Networking
    Replies: 1
    Last Post: 17th June 2008, 11:01 PM
  3. I get all forum's messages on email
    By linker in forum Suggestions & Feedback
    Replies: 1
    Last Post: 9th August 2005, 12:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •