Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Small HowTo] Utenti connessi ad un PDC samba
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
oleo
Tux's lil' helper
Tux's lil' helper


Joined: 09 Nov 2004
Posts: 117

PostPosted: Wed Jun 29, 2005 8:13 am    Post subject: [Small HowTo] Utenti connessi ad un PDC samba Reply with quote

Ciao!
Questo piccolo script bash determina gli utenti connessi ad un PDC samba. Io lo uso, integrato in un altro script, per spegnere il PDC ad una determinata ora, se nessun utente è connesso.
Code:

#!/bin/bash
SMBUSERS=`/usr/bin/smbstatus -b|/usr/bin/tail -n 8|/usr/bin/sed -e '/------/d' -e '/PID/d' -e '/Samba version/d' -e '/^$/d'|/usr/bin/awk -F ' ' '{print $2;}'`
SMBUSERCOUNT=0

for SMBUSER in $SMBUSERS
do
  echo $SMBUSER           #nome di ciascun utente
  let "SMBUSERCOUNT += 1"
done
echo $SMBUSERCOUNT   #numero di utenti connessi
exit 0


Con smbstatus -b ottengo un piccolo resoconto degli utenti connessi, su che macchina, che ip, ecc...
Code:
Samba version 3.0.10
PID     Username      Group         Machine
-------------------------------------------------------------------
 7716   fabio         users         athlon         (192.168.0.3)
 7718   giulia        users         asus           (192.168.0.2)
 7720   pat           users         centurion      (192.168.0.6)

poi con tail filtro solo le ultime 8 righe e con sed elimino nell'ordine la riga di trattini, la riga delle etichette (PID, Username, Group, ...) e poi quella con la versione di Samba.
Rimane solo:
Code:
 7716   fabio         users         athlon         (192.168.0.3)
 7718   giulia        users         asus           (192.168.0.2)
 7720   pat           users         centurion      (192.168.0.6)

Poi con awk divido le righe in campi (suddivisi da spazi) e tengo il secondo (ovvero il nome utente). Se si vuole ottenere il nome della macchina in cui un utente è loggato si dovrà sostituire print $2 con print $4.
Spero sia utile anche ad altri,
Fabio.
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