PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > awk and uniq
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

awk and uniq

Réponse
 
LinkBack Outils de la discussion
Vieux 29/05/2007, 03h19   #1
merrittr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut awk and uniq

I am trying to get the script below to mail out 1 email to each person
logged in however:

finger gives
bash-3.1$ finger
Login Name Tty Idle Login Time Office
Office Phone
rwm132 Robert Wesley Merritt pts/0 May 28 18:51
(reif.usask.ca)
rwm132 Robert Wesley Merritt *pts/1 51d May 24 18:53
(reif.usask.ca)
rwm132 Robert Wesley Merritt *pts/5 51d May 25 08:28
(reif.usask.ca)
rwm132 Robert Wesley Merritt *pts/2 51d May 25 11:00
(reif.usask.ca)
so I only want to send onee email, any ideas how i do that




#!/bin/sh

allnsid=""
finger | awk '{print $1} {print $2} {print $4}'|while read nsid
do
read fn
read ln
allnsid="$allnsid $nsid"
echo "hello $fn $ln" >> $nsid.txt
echo "please" >> $nsid.txt
echo "lof off " >> $nsid.txt
echo "the" >> $nsid.txt
echo "machine" >> $nsid.txt
#mail -s logoff $nsid@mail.usask.ca < $nsid.txt

case $allnsid in
*$nsid*)
echo "mailing to $nsid $fn $ln"
;;
esac

echo $allnsid
done

  Réponse avec citation
Vieux 29/05/2007, 05h14   #2
Harry331
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk and uniq

merrittr wrote...
>
>I am trying to get the script below to mail out 1 email to each person
>logged in however:


man wall

Wall displays the contents of file or, by default, its standard input, on
the terminals of all currently logged in users.


  Réponse avec citation
Vieux 29/05/2007, 11h39   #3
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk and uniq

merrittr wrote:
> I am trying to get the script below to mail out 1 email to each person
> logged in however:
>
> finger gives
> bash-3.1$ finger
> Login Name Tty Idle Login Time Office
> Office Phone
> rwm132 Robert Wesley Merritt pts/0 May 28 18:51
> (reif.usask.ca)
> rwm132 Robert Wesley Merritt *pts/1 51d May 24 18:53
> (reif.usask.ca)
> rwm132 Robert Wesley Merritt *pts/5 51d May 25 08:28
> (reif.usask.ca)
> rwm132 Robert Wesley Merritt *pts/2 51d May 25 11:00
> (reif.usask.ca)
> so I only want to send onee email, any ideas how i do that
>
>
>
>
> #!/bin/sh
>
> allnsid=""
> finger | awk '{print $1} {print $2} {print $4}'|while read nsid
> do
> read fn
> read ln
> allnsid="$allnsid $nsid"
> echo "hello $fn $ln" >> $nsid.txt
> echo "please" >> $nsid.txt
> echo "lof off " >> $nsid.txt
> echo "the" >> $nsid.txt
> echo "machine" >> $nsid.txt
> #mail -s logoff $nsid@mail.usask.ca < $nsid.txt
>
> case $allnsid in
> *$nsid*)
> echo "mailing to $nsid $fn $ln"
> ;;
> esac
>
> echo $allnsid
> done
>


Maybe you can use
wall
that will send a broadcast message to all terminals (shells).

Maybe you have
getent passwd
this works better than finger.

#!/bin/sh
getent passwd |
awk -F: 's[$1]++==0 && s[$3]++==0 {print $1":"$5}'
while read line
do
IFS=":"
set $line
echo "
Hello $2

please log off." |
mail -s logoff $1@mail.usask.ca
done

The awk line eliminates duplicates of fields 1 (ID) and 3 (UID).


--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 30/05/2007, 10h47   #4
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk and uniq

In article <1180405184.971791.263810@o11g2000prd.googlegroups .com>,
merrittr <merrittr@gmail.com> wrote:

> I am trying to get the script below to mail out 1 email to each person
> logged in however:
>
> finger gives
> bash-3.1$ finger
> Login Name Tty Idle Login Time Office
> Office Phone
> rwm132 Robert Wesley Merritt pts/0 May 28 18:51
> (reif.usask.ca)
> rwm132 Robert Wesley Merritt *pts/1 51d May 24 18:53
> (reif.usask.ca)
> rwm132 Robert Wesley Merritt *pts/5 51d May 25 08:28
> (reif.usask.ca)
> rwm132 Robert Wesley Merritt *pts/2 51d May 25 11:00
> (reif.usask.ca)
> so I only want to send onee email, any ideas how i do that
>
>
>
>
> #!/bin/sh
>
> allnsid=""
> finger | awk '{print $1} {print $2} {print $4}'|while read nsid
> do
> read fn
> read ln
> allnsid="$allnsid $nsid"
> echo "hello $fn $ln" >> $nsid.txt
> echo "please" >> $nsid.txt
> echo "lof off " >> $nsid.txt
> echo "the" >> $nsid.txt
> echo "machine" >> $nsid.txt
> #mail -s logoff $nsid@mail.usask.ca < $nsid.txt
>
> case $allnsid in
> *$nsid*)
> echo "mailing to $nsid $fn $ln"
> ;;
> esac
>
> echo $allnsid
> done


finger | awk '{fullname[$1]=$2 " " $4 }
END {for (id in fullname) print id, fullname[id]}' | \
while read nsid fn ln
do
mail -s logoff $nsid@mail.usask.ca <<EOF
hello $fn $ln
please
log off
the
machine
EOF
done

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h38.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12321 seconds with 12 queries