Skip to content

Instantly share code, notes, and snippets.

@InFog
Created February 22, 2016 10:13
Show Gist options
  • Select an option

  • Save InFog/bf2d7058631f0aaa9883 to your computer and use it in GitHub Desktop.

Select an option

Save InFog/bf2d7058631f0aaa9883 to your computer and use it in GitHub Desktop.

Revisions

  1. InFog created this gist Feb 22, 2016.
    52 changes: 52 additions & 0 deletions intrun
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/usr/bin/env python2
    #
    # This script will run something every 2 seconds and print a line in between
    #
    # Usage: intrun command

    from subprocess import call
    from sys import argv, exit
    from time import sleep


    def show_help():
    print "Command to run is missing!\n\tUsage %s command\n" % argv[0]


    def validate_input():
    if len(argv) != 2:
    return False
    return True


    def get_command():
    return argv[1]


    def print_line():
    print "\n"
    print "-" * 120
    print "\n"


    def main():
    if not validate_input():
    show_help()
    return 1

    command = get_command()

    while True:
    try:
    call(command)
    print_line()
    sleep(2)
    except KeyboardInterrupt:
    return 0
    except OSError:
    print "Command '%s' not found\n" % command
    return 2


    if __name__ == "__main__":
    exit(main())