Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[TIP]-[HOWTO] [Check Mail For Bash]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Risorse italiane (documentazione e tools)
View previous topic :: View next topic  
Author Message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 8:51 am    Post subject: [TIP]-[HOWTO] [Check Mail For Bash] Reply with quote

Programma ideato da Koma e realizzato da Comio:

check4mail
L'idea:

L'idea era quella di realizzare un programmino che mi permettesse di vedere se avevo messaggi di posta elettronica senza l'utilizzo di procmail o simili.


Necessario:

    fetchmail
    bash
    email con accesso smtp o pop
    crontab


Emergere fetchmail

Code:
emerge fetchmail



Configurare Fetchmail

Esempio di configurazione di .fetchmailrc da mettere nella vostra home:
Code:
poll POP.DEL.SERVER timeout 60 with proto POP3
user "USERNAMEDELLAMAIL" there
with password "PASSWORD-CHANGE-ME"
is VOSTROUTENTELOCALE here options keep



Eseguibile

Da utente:
Code:
$touch check4mail
$chmod +x check4mail
$nano check4mail

Scrivete all'interno il seguente codice:
Code:



#!/bin/bash 
for arg in $*; do               
   case "${arg}" in
      -h|--help)
         echo "HELP"
         echo "----"
         echo "-v --version Mostra la Versione"
         echo "-h --help    Mostra questo Help"
         echo "-e --cat     Mostra lo stato degli account dopo l'ultimo check"
    echo "-c --check   Controlla la posta (default)"
         exit
         ;;
      -v|--version)
         echo "Versione 0.01a By Comio & Koma"
         exit
         ;;
      -e|--cat)
         cat ~/.filefetchrc
         exit
         ;;
      -c|--check)
         ;;
      *)
         echo "Parametro non riconosciuto"
         exit
         ;;
      esac
done

fetchmail -c > .filefetchrc

cat ~/.filefetchrc |grep message |awk '
        { acc+=$1 }
    END { if (acc==0)
             printf("No Mail");
          else if (acc==1)
             printf("1 Mail");
          else
             printf("%d Mails", acc);
        }' > ~/.mail_count

Da root spostatelo nella directory /usrlocal//bin:
Code:
#mv check4mail /usr/local/bin


(TESTATELO DA USER PER EVITARE DANNI!)


Editare il profilo

Dato che è un programma che va bene per ogni utente editate /etc/profile se invece preferite farlo per il vostro singolo utente editate .bashrc
la stringa da usare è la seguente:
Code:
export PS1='\[\033[01;32m\][`cat ~/.mail_count`] \u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'



Editare il crontab

Per ogni utente è necessario avere un crontab diverso dato che il programma lavorerà sulle directory $HOME ( ~/ ) e userà per ogni utente il comando con un file per il fetch e una path diversi.
nel mio caso ho fatto così:
Code:
#crontab -u UTENTE -e
All'interno ho scritto questo che è l'equivalente di un controllo ogni 5 minuti
Code:
*/5 * * * *  /usr/local/bin/check4mail -c >> /dev/null



Il Bash Prima e Dopo

Il nostro bash prima di iniziare appariva così:
Code:
 utente@hostmacchina utente $

Adesso apparirà così:
Code:

[No Mail] utente@hostmacchina utente $
o così
[1 Mail] utente@hostmacchina utente $
o così
[N° Mails] utente@hostmacchina utente $


Good Work bros!

Edit 1/02/05
La path nel crontab deve essere completa
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD


Last edited by koma on Wed Feb 01, 2006 4:19 pm; edited 18 times in total
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30837
Location: here

PostPosted: Thu May 27, 2004 8:54 am    Post subject: Reply with quote

Non vorrei sbagliarmi ma mi pare che ci sia ora faccio una ricerca e vede se lo trovo.
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 8:57 am    Post subject: Reply with quote

fedeli in vena di proposte.. mi sposi? :D WHAHWHAWHAHW
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
MyZelF
Bodhisattva
Bodhisattva


Joined: 25 Feb 2003
Posts: 2010
Location: Venice, Italy

PostPosted: Thu May 27, 2004 9:04 am    Post subject: Reply with quote

Lo script potrebbe controllare la posta e modificare di conseguenza il prompt (ovvero la variabile PS1).

[mod]P.S.: koma scommetto che con un po' di sforzo riuscirai a trovare un subject più adatto al topic...[/mod]
_________________
"Larry the Cow was a bit frustrated at the current state of Linux Distributions..."
Back to top
View user's profile Send private message
federico
Advocate
Advocate


Joined: 18 Feb 2003
Posts: 3272
Location: Italy, Milano

PostPosted: Thu May 27, 2004 10:03 am    Post subject: Reply with quote

Potresti provare a legare quella cosa che vuoi che faccia a shell a sidemail da testo che ha proprio un output simile a quello che cerchi, prova a scrivere a riccardo@sideralis.net xke' purtroppo i file non sono ancora on line...
_________________
Sideralis www.sideralis.org
Pic http://blackman.amicofigo.com/gallery
Arduino http://www.arduino.cc
Chi aveva potuto aveva spaccato
2000 pezzi buttati là
Molti saluti,qualche domanda
Semplice come musica punk
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 10:13 am    Post subject: Reply with quote

ok mandata la mail.. in attesa speriamo che fedeli riesca a trovare qst suo programmillo :)
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
Benve
l33t
l33t


Joined: 13 Mar 2003
Posts: 897
Location: Italy Romagna

PostPosted: Thu May 27, 2004 10:24 am    Post subject: Reply with quote

forse riesci a farlo con fetchmail
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 10:25 am    Post subject: Reply with quote

mi hai anticipato di tipo 2 millesimi di secondo ora faccio le mie prove ma se conoscete un programmillo un po' + facile dite pure ;)
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 10:41 am    Post subject: Reply with quote

Forse ho risolto mi rimane solo di fare un programma anche in bash che legga l'output di fetchmail.. ad esempio:
Code:

$ fetchmail
fetchmail: No mail for koma at popmail.email.it
fetchmail: No mail for Komettolo at popmail.email.it
fetchmail: No mail for koma at pop.fastwebnet.it


:) così mi dovrebbe segnalare No Mail :):

Code:

[No Mail] Koma@HellMachine.Com $

Per quanto poi riguarda la ridondanza dell'eseguire il comando credo basti una voce in crontab
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30837
Location: here

PostPosted: Thu May 27, 2004 10:56 am    Post subject: Reply with quote

Questo abbinato a quest'altro dovresti riuscire a fare quello che vuoi.
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 11:06 am    Post subject: Reply with quote

ok ci sono quasi...
adesso ipotizzo 3 tipi di output solo che nn so come posso farmi i conti.. mhh mi spiego meglio con un paio di esempi:

Mettiamo che di putput mi viene fuori questo sparato in un file tramite il comando
fetchmail -c >> .filefetchrc :
Code:

$ cat .filefetchrc3
3 messages (2 seen) for kom4@email.it at popmail.email.it (4957 octets).
fetchmail: No mail for the.koma@email.it at popmail.email.it
1 message for koma at pop.fastwebnet.it (1155 octets).


Il MIO output per PS1 dovrebbe essere una cosa del tipo:
Quote:
[4 NEW MAIL] koma@HellMachine.Com koma $

Ma come posso estrapolare queste informazioni dal file?
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 11:41 am    Post subject: Reply with quote

ci sono quasi ... non mi rimane che capire come diamine fare la somma di + cifre presenti in un file

Code:
cat test.txt |grep 'message' |awk '{print $1}'
3
1

:) Scusate se stresso ma mi sto divertendo un sacco a fare questo programmicolo
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 11:49 am    Post subject: Reply with quote

fedeliallalinea wrote:
Questo abbinato a quest'altro dovresti riuscire a fare quello che vuoi.
Fedeli io la posta la scarico con sylpheed nn ho un programma che me la scarichi perchè non mi sono sbattuto a confare procmail o simili :) preferisco un normale check di fetchmail e un piccolo programmino in bash ;)
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
comio
Advocate
Advocate


Joined: 03 Jul 2003
Posts: 2191
Location: Taranto

PostPosted: Thu May 27, 2004 12:03 pm    Post subject: Reply with quote

Code:
cat test.txt |grep 'message' |awk '{ acc+=$1} END { printf("%d", acc); }'


ecco come fare la somma.

ciao
_________________
RTFM!!!!

e

http://www.comio.it
:)
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 12:16 pm    Post subject: Reply with quote

e per redirigere l'output in una variabile BASH? del tipo $POPPA
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 12:58 pm    Post subject: Reply with quote

ok sono riuscito ora rimane solo da configurare il bashrc ... rimango un po' dubbioso del funzionamento cmq proviamo...
allora il file eseguibile che ho trovato è in /usr/bin
questo è il contenuto
Code:
fetchmail -c > .filefetchrc
SUCA=`cat .filefetchrc |grep 'message' |awk '{ acc+=$1} END { printf("%d", acc); }'`
echo $SUCA
Se qualcuno vuole provarlo nel frattempo perchè io ora esco e torno stasera.Saludos
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Thu May 27, 2004 9:29 pm    Post subject: Reply with quote

QUOTO IL PRIMO MESSAGGIO DEL TOPIC CHE STA PER DIVENTARE UN HOWTO GRAZIE A COMIO
koma wrote:
Ciao a tutti :) volevo chiedervi se avete idea di come poter realizzare un programmino stupido (come sapete nn sono ferrato in materia di programmazione).
Questo programmello dovrebbe fare una cosa del tipo:

-Daemon (controlla ogni tot i miei N indirizzi email)
-Bash Advise*
-Comando di show Subject e Sender**

*Invece del solito
Code:
koma@Hellmachine.com $

una cosa del tipo
Code:
[ 2 Mail ] koma@Hellmachine.com $


** Che faccia così:
Code:
$ ShowMail
1 - Sent From Pinco@pallino.net Sub: Oggi Si è spento il server
2 - Sent From GIGI Sub: Sono Gay
$

_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
comio
Advocate
Advocate


Joined: 03 Jul 2003
Posts: 2191
Location: Taranto

PostPosted: Fri May 28, 2004 6:17 am    Post subject: Re: [TIP]-[HOWTO] [Check Mail For Bash] Reply with quote

koma wrote:
... realizzato da Comio:


arrossisco... ho solo detto cosa cercare!

ciao!
_________________
RTFM!!!!

e

http://www.comio.it
:)
Back to top
View user's profile Send private message
randomaze
Bodhisattva
Bodhisattva


Joined: 21 Oct 2003
Posts: 9985

PostPosted: Fri May 28, 2004 9:21 am    Post subject: Re: [TIP]-[HOWTO] [Check Mail For Bash] Reply with quote

Come al solito faccio lo scassapalle e ti do alcue note:

koma wrote:
Da root:
#touch check4mail
#chmod +x check4mail
#nano check4mail

Non é necessario essere root per eseguire questi passi. (anzi... dato che non si sa mai se nello script ci sono scappate cose strane io farei e testerei da utente normale....)

koma wrote:

...
E spostatelo nella directory /usr/bin:
...


Mah, io lo metterei almeno in /usr/local/bin per distinguerlo meglio (oppure una directory /opt/my/bin o qualcosa di simile....)
_________________
Ciao da me!
Back to top
View user's profile Send private message
koma
Advocate
Advocate


Joined: 06 Jun 2003
Posts: 2702
Location: Italy

PostPosted: Fri May 28, 2004 11:32 am    Post subject: Reply with quote

io mi sono trovato meglio così dato che evito l'export di nuove directory cmq per sbagliare a scrivere quello script bisogna essere un po' babbi ;)
_________________
http://www.youtube.com/watch?v=_yoJI-Tl94g GLORY GLORY HYPNOTOAD
Back to top
View user's profile Send private message
comio
Advocate
Advocate


Joined: 03 Jul 2003
Posts: 2191
Location: Taranto

PostPosted: Fri May 28, 2004 12:00 pm    Post subject: Re: [TIP]-[HOWTO] [Check Mail For Bash] Reply with quote

randomaze wrote:
Come al solito faccio lo scassapalle e ti do alcue note:

...

Mah, io lo metterei almeno in /usr/local/bin per distinguerlo meglio (oppure una directory /opt/my/bin o qualcosa di simile....)


io credo che randomaze abbia ragione. Per buona educazione bisogna sempre evitare di fare troppa roba come root. Io credo che l'ideale è fare uno script come utente e dare i diritti di esecuzione. Ovviamente il suid di uno script non si fa... quindi problemi di sicurezza comunque non ce ne sono.

ciao
_________________
RTFM!!!!

e

http://www.comio.it
:)
Back to top
View user's profile Send private message
Jecko_Hee
Tux's lil' helper
Tux's lil' helper


Joined: 20 Aug 2003
Posts: 142
Location: Svizzera/Ticino

PostPosted: Tue Jan 11, 2005 10:14 pm    Post subject: Re: [TIP]-[HOWTO] [Check Mail For Bash] Reply with quote

Bello bello :D
chi volesse usarlo come me per gmail, deve fare una piccola modifica al file .fetchmailrc aggiungendo ssl in questo modo:

Code:

poll pop.gmail.com timeout 60 with proto POP3
user "USERNAMEDELLAMAIL@gmail.com" there
with password "PASSWORD-CHANGE-ME"
ssl
is VOSTROUTENTELOCALE here options keep


bye


EDIT: bah :x fa un po' schifo pero' gmail via pop3, vedo messaggi non letti per un sacco di tempo dopo che li ho letti su web.
_________________
Negli anni 60 una delle tante ragazze di Fonzie, dopo aver fatto "petting", gli disse: "FONZIE, SE NON TI LECCHI LE DITA GODI SOLO A META'!"

EVITIAMO GLI OT - LINEE GUIDA DEL FORUM
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Risorse italiane (documentazione e tools) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum