-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathafter
More file actions
executable file
·23 lines (18 loc) · 788 Bytes
/
after
File metadata and controls
executable file
·23 lines (18 loc) · 788 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 success, then execute a different command')
parser.add_argument('until_command', help='Command to execute until success')
parser.add_argument('finally_command', help='Command to execute upon success')
args = parser.parse_args()
print "I'll run this until it succeeds: \n%s" % args.until_command
print "Once it succeeds (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)