26 luglio 2010

Python Piccoli Tips di Sistema Gnu/Linux

Colpa del grande caldo che non si sopporta dalle mie parti, e il rischio concreto di friggere qualche componente hardware(oltre al bagno di sudore che si fà inevitabilmente stando faccia a faccia con un monitor), ho deciso di mettere in ferie Other to Think.

Anche se ad essere sincero fino in fondo, ne approfitto, nel modo più sereno e rilassato possibile, per fare delle scelte(anche importanti) riguardanti il futuro della mia vita terrestre.

Ci rivedremo prima di settembre con qualche interessante novità Buone Vacanze a Tutti.

Ritornando ai nostri Tips, sono piccole chiamate di moduli per l' utente locale:

mediante il modulo pwd possiamo tramite il parametro name in getpwnam recuperare delle voci dal database delle password dell' utente che sono : nome, password, ID utente-gruppo, nome completo, home-directory e la shell.

In [5]: import pwd

In [6]: pwd.getpwnam('archie')
Out[6]: pwd.struct_passwd(pw_name='archie', pw_passwd='x', pw_uid=500, pw_gid=500, pw_gecos='archie dog', pw_dir='/home/archie', pw_shell='/bin/bash')


In [8]: pwd.getpwuid(500)
Out[8]: pwd.struct_passwd(pw_name='archie', pw_passwd='x', pw_uid=500, pw_gid=500, pw_gecos='archie dog', pw_dir='/home/archie', pw_shell='/bin/bash')

il modulo resource invece e utile per leggere l'utilizzo delle risorse dei processi riguardo l' utente.

qui vediamo resource con il parametro RUSAGE_SELF, che richiede per l' utente informazioni relative al solo processo corrente.


In [9]: import resource
In [11]: resource.getrusage(resource.RUSAGE_SELF)
Out[11]: resource.struct_rusage(ru_utime=0.45393, ru_stime=0.13397899999999999, ru_maxrss=12604, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=3564, ru_majflt=31, ru_nswap=0, ru_inblock=13576, ru_oublock=184, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=710, ru_nivcsw=50)


mentre quest' altro parametro RUSAGE_CHILDREN richiede informazioni sui processi figli dell' utente.

In [13]: resource.getrusage(resource.RUSAGE_CHILDREN)
Out[13]: resource.struct_rusage(ru_utime=0.0, ru_stime=0.0, ru_maxrss=0, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=0, ru_majflt=0, ru_nswap=0, ru_inblock=0, ru_oublock=0, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=0, ru_nivcsw=0)

il modulo grp è simile al modulo pwd, la differenza e quella di restituire le voci del database dei gruppi. Si possono usare come parametri name e gid, che restituiscono dati sui gruppi di appartenenza e dati riguardanti l' ID dei gruppi.

In [22]: import grp
In [24]: grp.getgrall()
Out[24]:
[grp.struct_group(gr_name='root', gr_passwd='x', gr_gid=0, gr_mem=['root']),
grp.struct_group(gr_name='bin', gr_passwd='x', gr_gid=1, gr_mem=['root', 'bin', 'daemon']),
grp.struct_group(gr_name='daemon', gr_passwd='x', gr_gid=2, gr_mem=['root', 'bin', 'daemon']),
grp.struct_group(gr_name='sys', gr_passwd='x', gr_gid=3, gr_mem=['root', 'bin', 'adm']),
grp.struct_group(gr_name='adm', gr_passwd='x', gr_gid=4, gr_mem=['root', 'adm', 'daemon']),
grp.struct_group(gr_name='tty', gr_passwd='x', gr_gid=5, gr_mem=[]),
grp.struct_group(gr_name='disk', gr_passwd='x', gr_gid=6, gr_mem=['root']),
grp.struct_group(gr_name='lp', gr_passwd='x', gr_gid=7, gr_mem=['daemon', 'lp']),
grp.struct_group(gr_name='mem', gr_passwd='x', gr_gid=8, gr_mem=[]),
grp.struct_group(gr_name='kmem', gr_passwd='x', gr_gid=9, gr_mem=[]),
grp.struct_group(gr_name='wheel', gr_passwd='x', gr_gid=10, gr_mem=['root']),
grp.struct_group(gr_name='mail', gr_passwd='x', gr_gid=12, gr_mem=['mail']),
grp.struct_group(gr_name='uucp', gr_passwd='x', gr_gid=14, gr_mem=['uucp']),
grp.struct_group(gr_name='man', gr_passwd='x', gr_gid=15, gr_mem=[]),
grp.struct_group(gr_name='games', gr_passwd='x', gr_gid=20, gr_mem=[]),
grp.struct_group(gr_name='gopher', gr_passwd='x', gr_gid=30, gr_mem=[]),
grp.struct_group(gr_name='video', gr_passwd='x', gr_gid=39, gr_mem=[]),
grp.struct_group(gr_name='dip', gr_passwd='x', gr_gid=40, gr_mem=[]),
grp.struct_group(gr_name='ftp', gr_passwd='x', gr_gid=50, gr_mem=[]),
grp.struct_group(gr_name='lock', gr_passwd='x', gr_gid=54, gr_mem=[]),
grp.struct_group(gr_name='audio', gr_passwd='x', gr_gid=63, gr_mem=[]),
grp.struct_group(gr_name='nobody', gr_passwd='x', gr_gid=99, gr_mem=[]),
grp.struct_group(gr_name='users', gr_passwd='x', gr_gid=100, gr_mem=[]),
grp.struct_group(gr_name='floppy', gr_passwd='x', gr_gid=19, gr_mem=[]),
grp.struct_group(gr_name='vcsa', gr_passwd='x', gr_gid=499, gr_mem=[]),
grp.struct_group(gr_name='avahi-autoipd', gr_passwd='x', gr_gid=498, gr_mem=[]),
grp.struct_group(gr_name='oprofile', gr_passwd='x', gr_gid=16, gr_mem=[]),
grp.struct_group(gr_name='ntp', gr_passwd='x', gr_gid=38, gr_mem=[]),
grp.struct_group(gr_name='utmp', gr_passwd='x', gr_gid=22, gr_mem=[]),
grp.struct_group(gr_name='utempter', gr_passwd='x', gr_gid=35, gr_mem=[]),
grp.struct_group(gr_name='slocate', gr_passwd='x', gr_gid=21, gr_mem=[]),
grp.struct_group(gr_name='desktop_admin_r', gr_passwd='x', gr_gid=497, gr_mem=[]),
grp.struct_group(gr_name='desktop_user_r', gr_passwd='x', gr_gid=496, gr_mem=[]),
grp.struct_group(gr_name='dbus', gr_passwd='x', gr_gid=81, gr_mem=[]),
grp.struct_group(gr_name='rpc', gr_passwd='x', gr_gid=32, gr_mem=[]),
grp.struct_group(gr_name='jackuser', gr_passwd='x', gr_gid=495, gr_mem=[]),
grp.struct_group(gr_name='nscd', gr_passwd='x', gr_gid=494, gr_mem=[]),
grp.struct_group(gr_name='rpcuser', gr_passwd='x', gr_gid=493, gr_mem=[]),
grp.struct_group(gr_name='nfsnobody', gr_passwd='x', gr_gid=65534, gr_mem=[]),
grp.struct_group(gr_name='tcpdump', gr_passwd='x', gr_gid=72, gr_mem=[]),
grp.struct_group(gr_name='ccache', gr_passwd='x', gr_gid=492, gr_mem=[]),
grp.struct_group(gr_name='cdrom', gr_passwd='x', gr_gid=11, gr_mem=[]),
grp.struct_group(gr_name='tape', gr_passwd='x', gr_gid=33, gr_mem=[]),
grp.struct_group(gr_name='dialout', gr_passwd='x', gr_gid=18, gr_mem=[]),
grp.struct_group(gr_name='avahi', gr_passwd='x', gr_gid=491, gr_mem=[]),
grp.struct_group(gr_name='mailnull', gr_passwd='x', gr_gid=489, gr_mem=[]),
grp.struct_group(gr_name='smmsp', gr_passwd='x', gr_gid=488, gr_mem=[]),
grp.struct_group(gr_name='openvpn', gr_passwd='x', gr_gid=487, gr_mem=[]),
grp.struct_group(gr_name='rtkit', gr_passwd='x', gr_gid=486, gr_mem=[]),
grp.struct_group(gr_name='apache', gr_passwd='x', gr_gid=485, gr_mem=[]),
grp.struct_group(gr_name='smolt', gr_passwd='x', gr_gid=484, gr_mem=[]),
grp.struct_group(gr_name='sshd', gr_passwd='x', gr_gid=483, gr_mem=[]),
grp.struct_group(gr_name='torrent', gr_passwd='x', gr_gid=482, gr_mem=[]),
grp.struct_group(gr_name='haldaemon', gr_passwd='x', gr_gid=481, gr_mem=[]),
grp.struct_group(gr_name='pulse', gr_passwd='x', gr_gid=480, gr_mem=[]),
grp.struct_group(gr_name='pulse-access', gr_passwd='x', gr_gid=479, gr_mem=[]),
grp.struct_group(gr_name='stapdev', gr_passwd='x', gr_gid=478, gr_mem=[]),
grp.struct_group(gr_name='stapusr', gr_passwd='x', gr_gid=477, gr_mem=[]),
grp.struct_group(gr_name='gdm', gr_passwd='x', gr_gid=476, gr_mem=[]),
grp.struct_group(gr_name='archie', gr_passwd='x', gr_gid=500, gr_mem=[]),
grp.struct_group(gr_name='abrt', gr_passwd='x', gr_gid=475, gr_mem=[]),
grp.struct_group(gr_name='stap-server', gr_passwd='x', gr_gid=155, gr_mem=[])]

Arrivederci e Buone Vacanze a Tutti! ;-)

Nessun commento: