#!/usr/bin/python
import sys
import os
import time
duration = 1
commandDefault = 'clear;'
def watchOnCommand(command):
while True:
os.system(commandDefault)
print time.strftime('%Y-%m-%d %H:%M:%S')
os.system(command)
time.sleep(duration)
# Script starts from here
# if len(sys.argv) < 2:
# print 'No action specified.'
# sys.exit()
if sys.argv[1].startswith('--'):
option = sys.argv[1][2:]
# fetch sys.argv[1] but without the first two characters
if option == 'version':
print 'Version 1.0'
elif option == 'help':
print '''\
This program prints files to the standard output.
Any number of files can be specified.
Options include:
--version : Prints the version number
--help : Display this help'''
else:
print 'Unknown option.'
sys.exit()
elif sys.argv[1].startswith('-n'):
if isinstance(sys.argv[2],str):
duration = int(sys.argv[2])
command = sys.argv[3:]
commandStr = "".join(command)
try:
watchOnCommand(commandStr)
except KeyboardInterrupt:
print "\nexit"
sys.exit
except Exception as e:
print e.message;
raise
finally:
pass
else:
command = sys.argv[2:]
commandStr = "".join(command)
try:
watchOnCommand(commandStr)
except KeyboardInterrupt:
print "\nexit"
sys.exit
except Exception as e:
print e.message;
raise
finally:
pass