FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:windows:wincheck:index.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
os:windows:wincheck:index.html [2018/01/31 00:33]
kurihara
os:windows:wincheck:index.html [2018/05/13 23:19] (current)
kurihara
Line 1: Line 1:
 [[:index.html#OS Management|Top#OS Management]] [[:index.html#OS Management|Top#OS Management]]
-====== Windows Check (wincheck.py)=====+====== Windows Check with Fabric (wincheck.py)=====
  
 $FHHOME/fabfile/wincheck.py $FHHOME/fabfile/wincheck.py
Line 7: Line 7:
 \\ \\
  
-===== Operation =====+===== Operation with Fabric =====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
Line 14: Line 14:
 </sxh> </sxh>
  
-==== Ref. Remote Shell Commands ====+\\ 
 +==== How to Check to Use Fabric in Windows ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-echo xx.xx.xx.xx fab auth.pro -- hostname +ssh user01@xx.xx.xx.xx hostname 
-$ echo xx.xx.xx.xx | fab auth.pro -- sudo cat /etc/shadow+$ ssh user01@xx.xx.xx.xx "PowerShell.exe -Command Get-Host" 
 +</sxh> 
 + 
 +\\ 
 +==== Fabric one-line Task Examples ==== 
 +==Cmd.exe== 
 +<sxh bash toolbar:false gutter:false> 
 +fab -H xx.xx.xx.xx -u USER -p PASSWORD --shell="Cmd.exe /C" --no-pty -- hostname 
 +$ echo xx.xx.xx.xx | fab auth.winpro --shell="Cmd.exe /C" --no-pty  -- ipconfig /all 
 +</sxh> 
 + 
 +==PowerShell.exe== 
 +<sxh bash toolbar:false gutter:false> 
 +$ fab -H xx.xx.xx.xx -u USER -p PASSWORD --shell="" --no-pty -- "PowerShell.exe -Command Get-Host" 
 +$ fab -H xx.xx.xx.xx -u USER -p PASSWORD --shell="PowerShell.exe -Command" auth.wintib  --no-pty -- Get-Host 
 +</sxh> 
 + 
 +<sxh bash toolbar:false gutter:false> 
 +## This isn't work well. Why? Please tell me. 
 +$ fab -H xx.xx.xx.xx -u USER -p PASSWORD --shell="" --no-pty -- "PowerShell.exe -Command $PSVersionTable" 
 +$ fab -H xx.xx.xx.xx -u USER -p PASSWORD --shell="PowerShell.exe -Command" auth.wintib  --no-pty -- $PSVersionTable
 </sxh> </sxh>
  
Line 26: Line 47:
  
 <sxh python toolbar:false gutter:false> <sxh python toolbar:false gutter:false>
-import sys+import sys, os
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
-from fabric.operations import open_shell 
  
 FHHOME=os.environ["FHHOME"] FHHOME=os.environ["FHHOME"]
  
  
 +#------------------------------------------------------------------
 +# wincheck.ipconfig_all
 +#------------------------------------------------------------------
 +@task
 +def chcp437():
 +    """chcp 437 # Change LANG To English"""
 +    run("chcp 437", shell=False, pty=False)
 +
 +
 +#================================================================================
 +# Network
 +#================================================================================
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # wincheck.ipconfig_all # wincheck.ipconfig_all
Line 39: Line 71:
 @task @task
 def ipconfig_all(): def ipconfig_all():
-    env.shell = "Cmd.exe /C" +    run("ipconfig /all", shell=False, pty=False)
-    run("ipconfig /all")+
  
 +#------------------------------------------------------------------
 +# wincheck.netstat_rn
 +#------------------------------------------------------------------
 +@task
 +def netstat_rn():
 +    run("netstat -rn", shell=False, pty=False)
 +
 +#------------------------------------------------------------------
 +# wincheck.test_netconnection:host,port
 +#------------------------------------------------------------------
 +@task
 +def test_netconnection(host,port):
 +    """test_netconnection(host,port)"""
 +    run('PowerShell.exe -Command $ProgressPreference="SilentlyContinue', shell=False, pty=False)
 +    run("PowerShell.exe -Command Test-NetConnection %s -Port %s" (host,port), shell=False, pty=False)
 +
 +
 +
 +#================================================================================
 +# User
 +#================================================================================
 +#------------------------------------------------------------------
 +# wincheck.net_user
 +#------------------------------------------------------------------
 +@task
 +def net_user():
 +    """ user list"""
 +    run("net user", shell=False, pty=False)
 +
 +#------------------------------------------------------------------
 +# wincheck.net_user:
 +#------------------------------------------------------------------
 +@task
 +def net_user(user):
 +    run("net user %s" % user, shell=False, pty=False)
 +
 +#------------------------------------------------------------------
 +# wincheck.net_user_active:
 +#------------------------------------------------------------------
 +@task
 +def net_user_active(user):
 +    """ make user active from disable"""
 +    run("net user %s /active" % user, shell=False, pty=False)
 +
 +
 +#------------------------------------------------------------------
 +# wincheck.net_localgroup_administrators
 +#------------------------------------------------------------------
 +@task
 +def net_localgroup_administrators():
 +    run("net localgroup administrators", shell=False, pty=False)
 +
 +#------------------------------------------------------------------
 +# wincheck.net_localgroup_users
 +#------------------------------------------------------------------
 +@task
 +def net_localgroup_users():
 +    run("net localgroup users", shell=False, pty=False)
 +
 +
 +
 +#================================================================================
 +# etc
 +#================================================================================
 +#------------------------------------------------------------------
 +# wincheck.systeminfo
 +#------------------------------------------------------------------
 +@task
 +def systeminfo():
 +    run("systeminfo", shell=False, pty=False)
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
Line 48: Line 149:
 @task @task
 def powershell_version(): def powershell_version():
-    env.shell = "PowerShell.exe -Command+    run("PowerShell.exe -Command $PSVersionTable", shell=False, pty=False)
-    run($PSVersionTable)+
  
  


os/windows/wincheck/index.html.1517326410.txt.gz · Last modified: 2018/01/31 00:33 by kurihara