import serial
import datetime
ser = serial.Serial("/dev/ttyUSB0", 9600)
log = open('/opt/share/www/'+datetime.datetime.now().strftime("%Y.%m.%d")+'.txt','a+')
while 1:
print >> log , datetime.datetime.now().strftime("%y %m %d %H %M %S ") , ser.readline(),
import signal
def sigterm_handler(signal, stack_frame):
log.close()
exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)