I have written a little script in Python that I use to append text to a work log. I have placed the script in a directory in my $PATH
#!/usr/bin/python
# import necessary modules
import sys
import os
import datetime
# main() function
def main():
now = datetime.datetime.now()
tmp = ' '.join(sys.argv[1:])
outfile = '/path/to/output/done.log'
outstr = now.strftime("%Y-%m-%d %H:%M:%S") + ' - ' + tmp + '\n'
f=open(outfile,'a')
f.write(outstr)
f.close()
# print sys.argv[0:1]
print 'Adding ' + outstr
# Call main()
if __name__ == '__main__':
main()
When I run the script as in example 1, I get an error.
Example 1:
host:scripts user$ done this is a test
-bash: syntax error near unexpected token `done'
If I run the script as in example 2, it behaves as expected.
Example 2:
host:scripts user$ python done this is a test
Adding 2012-11-15 09:57:44 - this is a test
How do I get this to work in the first example?