I have included the entire source. I am getting the traceback error.

import os
import sys
import fileinput
import datetime
from time import localtime
name = sys.argv[1]
# log specifies the file that is supposed to be parsed by the script
log = fileinput.input('/var/log/secure.log')
L = localtime()
CalendarMonth = L[1]
today = L[2]
Month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
MonthVar = CalendarMonth - 1
MonthName = Month[MonthVar]
#
#def timetest determines whether the user logged in within the last hour
#
def timetest(hour,min, sec, Hour, Min, Sec):


    x = (int(hour)*60)+int(min)+(int(sec)/60) - 180


        y = (int(Hour)*60)+int(Min)+(int(Sec)/60)
        if y >= x:
                z = 'true'
        else:
                z = 'false'
        return z
login = 'User info context values set for'
logwindow = 'Showing Login Window'
failedauth = 'Failed to authenticate'
firstlist = []
for line in log:


    if MonthName in line:


                h = line.split()
                day = float(h[1])
                if day == today:
                        if login in line:
                                firstlist.append(line)
                        elif failedauth in line:
                                firstlist.append(line)
                        elif logwindow in line:
                                firstlist.append(line)
                        else: pass
                else: pass
        else: pass
firstlistlength = int(len(firstlist))
if firstlistlength == 0:


    pass


else:


            count1 = 0


        count2 = 0
        actuallist = []
        while count1 <= count2:
                if count1 == count2:
                        tryline = firstlist[count1]
                        count3 = count1 + 1
                        try:
                                nextline = firstlist[count3]
                        except IndexError:
                                actuallist.append(tryline)
                                break
                        if login in tryline:
                                if failedauth in nextline:
                                        count1 = count1 + 1
                                        count2 = count2 + 1
                                else:
                                        actuallist.append(tryline)
                                        count1 = count1 + 1
                                        count2 = count2 + 1
                        else:
                                count1 = count1 + 1
                                count2 = count2 + 1
                else:
                        pass
if firstlistlength == 0:
 pass
else:
 actuallist.reverse()
 lastlogin = []
 namelist = []
 for line in actuallist:
  if name in namelist:
   pass
  elif name in line:
   lastlogin.append(line)
   namelist.append(name)
  else:
   lastlogin.append(line)
   intlastlogin = int(len(lastlogin))
   if int(len(namelist)) == 0:


          pass


 else:
  if intlastlogin == 1:
   #this is were the actual rsync command is executed
   rsync = 'rsync -rlptoDuz --ignore-errors --bwlimit=3000 --exclude-from=/home/shared/sync/exclude --delete /home/'+name+'/ /Volumes/local/io-works/home/'+name+'/'
   os.system(rsync)
  else:
   intnextline = int(intlastlogin - 2)
   nextline = lastlogin[intnextline]
   sys.stdout.write(nextline)
   sys.stdout.write('\n')
   tim = datetime.datetime.now()
   hour = '%d' %tim.hour
   min = '%d' %tim.minute
   sec = '%d' %tim.second
   index1 = nextline.split()
   Time = index1[2]
   Hour = Time[:2]
   Min = Time[3:5]
   Sec = Time[6:]
   test = timetest(hour,min, sec, Hour, Min, Sec)
if test == 'true':


                      #this is were the actual rsync command is executed


    rsync = 'rsync -rlptoDuz --ignore-errors --bwlimit=3000 --exclude-from=/home/shared/sync/exclude --delete /home/'+name+'/ /Volumes/local/io-works/home/'+name+'/'
    os.system(rsync)
else:


           pass




**Error:**
Traceback (most recent call last):
** IDLE Internal Exception: 
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/idlelib/run.py", line 334, in runcode


        exec(code, self.locals)


  File "/home/ldaniel/Desktop/run.py", line 6, in <module>

IndexError: list index out of range

Please help me

Edited 3 Years Ago by Dani: Formatting fixed

name = sys.argv[1] means that you most give argument from Command-line.
run.py something if you dont give argument from Commad-line you get IndexError: list index out of range
Read about sys.argv

Your code is messy.

        else: pass
    else: pass
else: pass

This is not good at all.

Edited 3 Years Ago by snippsat

This article has been dead for over six months. Start a new discussion instead.