Re: Cron Job Output

2009-12-02 Thread LoD MoD
You might try something like this http://code.activestate.com/recipes/157035/


On Wed, Dec 2, 2009 at 3:05 PM, baytes  wrote:
> I have cron checking services every 5-10 minutes, and if a service
> goes up or down it writes to a file, Im trying to write a script that
> will check that file for updates and print the results. this will tie
> into a module for phenny where the bot will be able to print the
> contents of the updated file to the channel.
>
> Im extremely new to python and any point in the right direction or
> tutorials on the subject would be greatly appreicated.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib post and redirect = fail

2009-12-10 Thread LoD MoD
I'm trying to do a post to log into a simple admin console. All I get
is a simple you need to log in error. I already mapped the form id's
to make sure they are correct, but it still seems to deny.
I know mechanize would probably do a better job of this than urllib,
but their docs for python aren't available online right now. Any help
is appreciated.


import urllib, urllib2

# build opener with HTTPCookieProcessor
o = urllib2.build_opener( urllib2.HTTPCookieProcessor() )
urllib2.install_opener( o )

# assuming the site expects 'user' and 'pass' as query params
#p = urllib.urlencode( { 'j_character_encoding' : 'UTF-8',
'j_username': 'cooduser', 'j_password': 'password' } )
p = urllib.urlencode(dict(j_username='cooduser', j_password='password'))
# perform login with params
f = o.open( 'http://myserver:5000/login/LoginForm.jsp',  p )
data = f.read()
f.close()
print data

Here is the form source:

  



  
  Authentication Denied

  The username or password has been refused by Server.
Please try again.



  
  

Username:

  


  
  

  Password:

  

  

  

  


  


The response code is 200.

Here is the header info from f.info() :
Cache-Control: no-cache
Connection: close
Date: Fri, 11 Dec 2009 01:29:40 GMT
Pragma: no-cache
Content-Length: 3534
Content-Type: text/html; charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: 
NCONSOLESESSION=QwcDLhgG5NrxJGBQJfpv1dynvpddjT4LJTHnGhYz9ZDl6R9Pzqvh!2016686010;
path=/
X-Powered-By: Servlet/2.5 JSP/2.1
-- 
http://mail.python.org/mailman/listinfo/python-list


getopt code NameError exception on logTail.py

2009-07-17 Thread LoD MoD
I am having trouble extending my option parsing.

Any help is appreciated:


import sys

import getopt

import time


def tail(file):

while 1:

where = file.tell()

line = file.readline()

if not line:

time.sleep(1)

file.seek(where)

else:

print line, # already has newline


def main():



# parse command line options

try:

opts, args = getopt.getopt(sys.argv[1:], "hf:", ["help", "filename="
])

except getopt.error, msg:

print msg

print "for help use --help"

sys.exit(2)

# process options

for o, a in opts:

if o in ("-h", "--help"):

print __doc__

sys.exit(0)

if o in ("-f", "--filename"):

print "Parsing F argument"

file = open(filename, 'r')

print file






# process arguments

for arg in args:

process(arg) # process() is defined elsewhere


if __name__ == "__main__":

main()

Yields this error:

localhost:src gsery$ python logTail.py  /var/log/system.log
Traceback (most recent call last):
  File "logTail.py", line 52, in 
main()
  File "logTail.py", line 49, in main
process(arg) # process() is defined elsewhere
NameError: global name 'process' is not defined
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getopt code NameError exception on logTail.py

2009-07-17 Thread LoD MoD
In this instance the trackback was somewhat unhelpful.There problem was
here:

   file = open(filename, 'r')

should be

   file = open(a, 'r')

args should be passed within the getopt riff

On Fri, Jul 17, 2009 at 11:08 AM, MRAB  wrote:

> LoD MoD wrote:
>
>> I am having trouble extending my option parsing.
>> Any help is appreciated:
>>
>> import sys
>> import getopt
>> import time
>>
>> def tail(file):
>>while 1:
>>where = file.tell()
>>line = file.readline()
>>if not line:
>>time.sleep(1)
>>file.seek(where)
>>else:
>>print line, # already has newline
>>
>> def main():
>>
>># parse command line options
>>try:
>>opts, args = getopt.getopt(sys.argv[1:], "hf:", ["help",
>> "filename="])
>>except getopt.error, msg:
>>print msg
>>print "for help use --help"
>>sys.exit(2)
>># process options
>>for o, a in opts:
>>if o in ("-h", "--help"):
>>print __doc__
>>sys.exit(0)
>>if o in ("-f", "--filename"):
>>print "Parsing F argument"
>>file = open(filename, 'r')
>>print file
>>
>># process arguments
>>for arg in args:
>>process(arg) # process() is defined elsewhere
>>
>> if __name__ == "__main__":
>>main()
>>
>> Yields this error:
>>
>> localhost:src gsery$ python logTail.py  /var/log/system.log
>> Traceback (most recent call last):
>>  File "logTail.py", line 52, in 
>>main()
>>  File "logTail.py", line 49, in main
>>process(arg) # process() is defined elsewhere
>> NameError: global name 'process' is not defined
>>
>>  The trackback tells you what's wrong: you haven't defined 'process'. The
> comment says it's defined elsewhere, but neither I nor Python can see
> it! :-)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


creating my own logwatch in python

2009-07-17 Thread LoD MoD
I am trying to fabricate a logwatch-type script in Python and I'm having
some trouble.What happens with the following code is that it prints to the
screen but the if condition on line 22 never gets executed.

http://pastie.org/549975

Any suggestions are appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list