1

I have a task, write a shell-script, that: - All e-mails, that received by the user specified by the first parameter, sends to the currently running system users; - If sender is online, input from the terminal message and send to this user.

This script:

#!/bin/bash

#####Static variables#####
SENDER=$1
MSG=''
MSG4S=''

#####Functions#####
gtmsg () {
        echo "p * f $SENDER" | mail | sed '1,/samos/ d' | sed '/Saved/,$ d'
}

sndmsg () {
        /usr/bin/who |
        while read W
        do
                NAME=$(echo "$W" | awk '{printf $1}')

                if [ "$NAME" != "$SENDER" ]
                then
                        echo "$MSG" | mail -s "New mail from $SENDER" "$NAME"
                else
                        echo "Print message for sender: "
                        read MSG4S
                        echo "$MSG4S" | mail -s "New mail for $SENDER" "$SENDER"
                fi
done
}

hlp () {
        echo "$0: sender"
}

#####Main#####
case $# in
        1) MSG=$(gtmsg)
           echo $MSG
           if [ -n "$MSG" ]
           then
                sndmsg
           else
                echo "No mail from $SENDER"
           fi
           ;;
        *) hlp
           ;;
esac

I have a 2 trouble:

  1. How print message from mail without header?
  2. read running abinormaly: is running only 1 sec and off. I try used mail -t 30, but trouble not solved.

0

You must log in to answer this question.

Browse other questions tagged .