forked from davidohana/peasyshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_app.py
executable file
·34 lines (22 loc) · 1 KB
/
sample_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python2
from peasyshell import *
init_logging()
sh("ls -al", log_process_id=True)
sh("ping 127.0.0.1", timeout_sec=3, echo_cmd=False, echo_cmd_args=True)
sh("""cat peasyshell.py
| grep import""", shell=True, shell_single_command=True)
hostname = sh("hostname -f", capture_out=True, output_remove_trailing_newlines=True).stdout
print("my hostname is [{}]".format(hostname))
sh("hostname -f", capture_out=True, output_remove_trailing_newlines=False)
print("my hostname is [{}]".format(shres.stdout))
os.environ["my_var1"] = "foo"
sh("echo **$my_var1**", shell=True)
sh("echo **$my_var2**", shell=True, env={"my_var2": "bar"})
out = sh("ps aux | grep sample_app | grep -v grep", shell=True, capture_out=True).stdout
pid = out.split()[1]
print("my process ID: " + pid)
exit_on_fail = yes_or_no("exit on fail?")
# next command will fail because -X arg does not exist
# and as a result the python script will terminate
sh("hostname -X", exit_on_fail=exit_on_fail, log_process_id=True)
print ("bye")