-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfinally
More file actions
executable file
·23 lines (18 loc) · 783 Bytes
/
finally
File metadata and controls
executable file
·23 lines (18 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
import argparse
import subprocess
# Parse command line arguments
parser = argparse.ArgumentParser(
description='Execute a command until fails, then execute a different command')
parser.add_argument('until_command', help='Command to execute until failure')
parser.add_argument('finally_command', help='Command to execute upon failure')
args = parser.parse_args()
print "I'll run this until it fails: \n%s" % args.until_command
print "Once it fails (exit code != 0), I'll run: \n%s" % args.finally_command
working = False
times = 0
while working is not True:
working = subprocess.call(args.until_command, shell=True) != 0
times += 1
print "I've run this command {0} times so far...".format(times)
subprocess.call(args.finally_command, shell=True)