Discussion:
[Fab-user] fabric std output to file
Kaushal Shriyan
2016-07-18 12:24:04 UTC
Permalink
My fabric python script is here

######################################################
from fabric.api import *

env.hosts = ['192.168.1.215','192.168.1.168','192.168.1.99']

def checkconn():
run('w')
def checkdisk():
run('df -hT --total')
######################################################

$*fab checkconn* should write to a file in the local system instead of
stdout on the console. For example output of "w" command run on the remote
server should be written to a file locally.

Any help will be highly appreciable

Regards,

Kaushal
Brandon Whaley
2016-07-18 14:13:08 UTC
Permalink
There are two approaches here. The first is to open a file and write the
result of the 'w' command from within checkconn, the other is to redirect
from the shell.

$ fab checkconn > checkconn_result.log

OR

def checkconn():
result = run('w')
with open('checkconn_result.log', 'w') as f:
f.write(result)
Post by Kaushal Shriyan
My fabric python script is here
######################################################
from fabric.api import *
env.hosts = ['192.168.1.215','192.168.1.168','192.168.1.99']
run('w')
run('df -hT --total')
######################################################
$*fab checkconn* should write to a file in the local system instead of
stdout on the console. For example output of "w" command run on the remote
server should be written to a file locally.
Any help will be highly appreciable
Regards,
Kaushal
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Kaushal Shriyan
2016-07-18 14:24:46 UTC
Permalink
Post by Brandon Whaley
There are two approaches here. The first is to open a file and write the
result of the 'w' command from within checkconn, the other is to redirect
from the shell.
$ fab checkconn > checkconn_result.log
OR
result = run('w')
f.write(result)
Thank you Brandon for the suggestion.

Regards,

Kaushal

Loading...