From: Uwe Zessin [zessin@my-deja.com] Sent: Wednesday, June 14, 2000 3:30 PM To: Info-VAX@Mvb.Saic.Com Subject: Re: Seaching SYSUAF.DAT In article <8i8bij$33l$1@nnrp1.deja.com>, trdorr@my-deja.com wrote: > I'm looking for a way to search SYSUAF.DAT for accounts that have not > been active for greater than 30 days and less than 60 days. Is there a > way to use the LAST Login date to produce a list of users that are > inactive? > Thanks, > Tom Here is a small Python script I have just put together. As an added bonus it also reports the number of logfails. #++ # UAF_FIND_INACTIVE_BETWEEN.PY -- 14-JUN-2000 Uwe Zessin # # Find all users that have been inactive (having no login) # between two dates. You need to specify absolute date + # time; a combination time ("-90-") does not work. However # you can use DCL like this: # $ python UAF_FIND_INACTIVE_BETWEEN.PY - # _$ "''F$CVTIME("-90-","ABSOLUTE")'" - # _$ "''F$CVTIME("-30-","ABSOLUTE")'" # The program will also report the number of login failures. #-- import exceptions, pyvms, string, sys, vms_sys if (len(sys.argv) != 3): print 'ERROR: need 2 parameters' print ' parameter 1: start date' print ' parameter 2: end date' sys.exit(0) # uppercase month names - required on (some?) versions # of OpenVMS Alpha t_date_start = string.upper (sys.argv [1]) t_date_end = string.upper (sys.argv [2]) # convert string to binary date+time try: q_date_start = vms_sys.bintim (t_date_start) except exceptions.Exception, e: print 'ERROR: failed to convert start date' print e.args sys.exit(0) # convert string to binary date+time try: q_date_end = vms_sys.bintim (t_date_end) except exceptions.Exception, e: print 'ERROR: failed to convert end date' print e.args sys.exit(0) if (q_date_start > q_date_end): print 'WARNING: start date is after end date - will swap' tmp = q_date_start q_date_start = q_date_end q_date_end = tmp if (q_date_start == q_date_end): print 'ERROR: both dates are equal' sys.exit(0) print 'accounts inactive between:', vms_sys.asctim (q_date_start) print ' and:', vms_sys.asctim (q_date_end) print '' RMS__EOF = 98938 # get contents of UAF uaf_dict = pyvms.uaf_get_usernames () # check status of operation l_sts = uaf_dict ['sts'] if (l_sts != RMS__EOF): l_stv = uaf_dict ['stv'] print vms_sys.getmsg (l_sts)[0] print vms_sys.getmsg (l_stv)[0] sys.exit(0) # pure list of usernames uaf_list = uaf_dict ['usernames'] x_header = 0 # loop over list if usernames for username in uaf_list: # get information about username uai_dict = vms_sys.getuai (None,None,username, \ ('UAI$_LASTLOGIN_I','UAI$_LOGFAILS')) # check status l_status = uai_dict ['status'] if (l_status != 1): print vms_sys.getmsg (l_status) sys.exit(0) # check last login q_lastlogin_i = uai_dict ['UAI$_LASTLOGIN_I'] if (q_lastlogin_i >= q_date_start) and \ (q_lastlogin_i <= q_date_end) : if (not x_header): x_header = 1 print '%12s %23s %s' % \ ('username', 'last login', 'logfails') print '------------------------------------------------' q_uai_lastlogin_i = uai_dict ['UAI$_LASTLOGIN_I'] if (q_uai_lastlogin_i == 0L): t_uai_lastlogin_i = 'Never Logged In' else: t_uai_lastlogin_i = vms_sys.asctim (q_uai_lastlogin_i) w_uai_logfails = uai_dict ['UAI$_LOGFAILS'] print '%12s %23s %i' % \ (username, t_uai_lastlogin_i, w_uai_logfails) ----- Examples: $ python UAF_FIND_INACTIVE_BETWEEN.PY 2-jan-2000 1-jan-1997 WARNING: start date is after end date - will swap accounts inactive between: 1-JAN-1997 20:58:28.04 and: 2-JAN-2000 20:58:28.04 username last login logfails ------------------------------------------------ NOPRIV 20-AUG-1999 22:13:20.21 0 RAYTRACE 18-APR-1997 18:35:03.39 1 $ $ python UAF_FIND_INACTIVE_BETWEEN.PY 1-jan-2000 xyz ERROR: failed to convert end date (388, '%SYSTEM-F-IVTIME, invalid time') $ $ python UAF_FIND_INACTIVE_BETWEEN.PY 1-jan-2000 ERROR: need 2 parameters parameter 1: start date parameter 2: end date $ $ python UAF_FIND_INACTIVE_BETWEEN.PY "''F$CVTIME("-90-","ABSOLUTE")'" - _$ "''F$CVTIME("-30-","ABSOLUTE")'" accounts inactive between: 16-MAR-2000 21:12:53.25 and: 15-MAY-2000 21:12:53.25 username last login logfails ------------------------------------------------ SYSTEM 11-MAY-2000 17:35:14.77 0 $ ----- You can find Python for OpenVMS at: http://www.decus.de/~zessin/python/ You can find some more examples at: http://www.decus.de/~zessin/python/doc/demo/toc_demo.html -- Uwe Zessin Sent via Deja.com http://www.deja.com/ Before you buy.