Fedora Linux Support Community & Resources Center
  #1  
Old 12th October 2017, 07:36 PM
Jeff Sadowski Offline
Registered User
 
Join Date: Jun 2005
Age: 43
Posts: 506
linuxchrome
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.
Reply With Quote
  #2  
Old 13th October 2017, 10:41 PM
Jeff Sadowski Offline
Registered User
 
Join Date: Jun 2005
Age: 43
Posts: 506
linuxchrome
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.
Reply With Quote
  #3  
Old 15th October 2017, 12:21 AM
Jeff Sadowski Offline
Registered User
 
Join Date: Jun 2005
Age: 43
Posts: 506
linuxchrome
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
}
Reply With Quote
Reply

Tags
email , messages , wall

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


Current GMT-time: 10:16 (Saturday, 21-10-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat