Showing posts with label Misc. Show all posts
Showing posts with label Misc. Show all posts

Thursday, April 7, 2011

Get/ Set informations on multiple HP Onboard Administrator / Virtual Connect - Example with setting password and show all

When you need to get informations (like "SHOW ALL") on more than 400 Onboard Administrator or Virtual Connect, production team is always happy when you can give them an automatic solution.

Before give you main script for that, let's explain some details:
HP Onboard Administrator or Virtual Connect can be connect by SSH using tools like putty (Alternative Download). When you are connect on your OA or VC you can use some command line.

For more information about OA command line go to Onboard Administrator dedicated HP site and specifically to OA download manual on Manual OA site to download HP BladeSystem Onboard Administrator Command Line Interface User Guide(Alternative Download)

For more information about VC command line go to Manual VC site where you could find HP Virtual Connect Manager Command Line Interface (Alternative Download)

To use plink.exe (tool to do putty link), on OA or VC, I give you some examples below

To create a new OA administrator user named admin with password pass

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAadduser.txt

with OAadduser.txt

ADD USER "admin" "pass"
SET USER ACCESS "admin" ADMINISTRATOR
SET USER FULLNAME "admin" "Backup Administrator"
ASSIGN SERVER ALL "admin"
ASSIGN INTERCONNECT ALL "admin"
ASSIGN OA "admin"


To change admin OA user password to newpass

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAchangepassword.txt

with OAchangepassword.txt

SET USER PASSWORD "admin" "newpass"


To delete admin OA user

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAremoveuser.txt

with OAremoveuser.txt

REMOVE USER "admin"


To show all OA informations

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAshowall.txt

with OAremoveuser.txt

SHOW ALL




To create a new VC administrator user named admin with password pass

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCadduser.txt

with VCadduser.txt

add user admin Password=pass Privileges="domain,server,network,storage" FullName="Backup Administrator" Enabled=true


To change admin VC user password to newpass

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCchangepassword.txt

with VCchangepassword.txt

set user admin Password=newpass


To delete admin VC user

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCremoveuser.txt

with VCremoveuser.txt

remove user admin


To show all VC informations

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCshowall.txt

with VCshowall.txt

SHOW ALL



Now the best part: do all these actions on multiple Onboard Administrator or Virtual Connect. If you do not want to do copy/paste for each part, I encourage you to download GetSetHPOAVCInfos.zip file file.

First, you must create putty ssh keys. For this, execute plink_reg.cmd which will create these key then will export registry to plink.reg file
Why create ssh keys before ? That permit to avoid to answer yes to each OA or VC

@Echo OFF
Rem
Rem Generate plink reg
Rem
Rem F.RICHARD
Rem Initial Version: 2010 August
Rem modification 2011 March : add filename parameter
Rem

SET CURDIR=%~d0%~p0
SET FILENAME=%~n0%~x0
If "%1"=="" goto :ERRORNOFILE

cd /d %CURDIR%
set inputfile=%1
If NOT EXIST %inputfile% GOTO :ERRORFILE

SET LOGFILE="%CURDIR%plink_reg.log"

If NOT EXIST plink.exe GOTO :ERRFILEPLINK
echo Begin %date% %time% > %LOGFILE%




For /F "tokens=1,2,3 delims=;" %%i in (%inputfile%) do call :doit %%i %%j %%k


echo End %date% %time% >> %LOGFILE%
regedit /E plink.reg "HKEY_CURRENT_USER\Software\SimonTatham"
goto :EOF




:doit
rem echo %1 %2 %3
IF {%1}=={} GOTO :ERRORLINE
IF {%2}=={} GOTO :ERRORLINE
IF {%3}=={} GOTO :ERRORLINE


Echo Reg plink %1 (%date% %time%)
Echo ----------------------------- >> %LOGFILE% 2>>&1
Echo Reg plink %1 (%date% %time%) >> %LOGFILE% 2>>&1
plink.exe -ssh -l %2 -pw %3 -batch %1 "exit" >> %LOGFILE% 2>>&1
goto :EOF



:ERRORLINE
Echo ERROR next line (something missing)
Echo %1;%2;%3
goto :EOF

:ERRORFILE
Echo ERROR file %inputfile% does not exist in %CURDIR% directory
goto :EOF

:ERRFILEPLINK
Echo ERROR: file plink.exe does not exist in %CURDIR% directory
Echo Execute plink.exe before executing this file
goto :EOF

:ERRORNOFILE
Echo ERROR You must specify a filename containing line with these informations
Echo ip_or_name;login;password
Echo Ex: run
Echo %FILENAME% myOA.txt
Echo with myOAVC.txt containing
Echo 192.168.1.251;Administrator;password
Echo 192.168.1.252;Administrator;password
echo.
goto :EOF



To use script GetSetHPOAVCInfos.cmd, which permit to execute command line on all VC or OA use for example

GetHPOAVCInfos.cmd testOAVC.txt testOAVCcmdline.txt

with file testOAVC.txt containing for example these lines

192.168.1.220;administrator;password
192.168.1.224;administrator;password

and file testOAVCcmdline.txt with these lines

show all


All informations are return in oa_or_vc.log file
If you want to separate each log (ex: oa_or_vc_192.168.1.220.log, oa_or_vc_192.168.1.224.log) add SEPARATELOG like this

GetHPOAVCInfos.cmd testOAVC.txt testOAVCcmdline.txt SEPARATELOG


GetSetHPOAVCInfos.cmd file

@Echo OFF
Rem
Rem Get Information in HP Onboard Administrator or Virtual Connect
Rem
Rem F.RICHARD
Rem August 2010
Rem modification 2011 March : add filename parameter
Rem

SET CURDIR=%~d0%~p0
SET FILENAME=%~n0%~x0
If "%1"=="" goto :ERRORNOFILE
If "%2"=="" goto :ERRORNOFILE
SET SEPARATELOG=NO
If "%3"=="SEPARATELOG" SET SEPARATELOG=YES

cd /d %CURDIR%
set inputfile=%1
If NOT EXIST "%inputfile%" GOTO :ERRORFILE

set actionfile=%2
If NOT EXIST "%actionfile%" GOTO :ERRORFILE2

SET separate=.log
SET LOGFILE=%CURDIR%oa_or_vc

If NOT EXIST plink.exe GOTO :ERRFILEPLINK
echo Begin %date% %time%
echo Begin %date% %time% > "%LOGFILE%%separate%"

If NOT EXIST plink.reg GOTO :ERRFILEPLINKREG
regedit /s plink.reg

For /F "tokens=1,2,3 delims=;" %%i in (%inputfile%) do call :doit %%i %%j %%k

SET separate=.log
echo End %date% %time%
echo End %date% %time% >> "%LOGFILE%%separate%"
goto :EOF





:doit
IF {%1}=={} GOTO :ERRORLINE
IF {%2}=={} GOTO :ERRORLINE
IF {%3}=={} GOTO :ERRORLINE


Echo Use %actionfile% file on %1 (%date% %time%)
If "%SEPARATELOG%"=="YES" SET separate=_%1.log
If "%SEPARATELOG%"=="YES" echo.> "%LOGFILE%%separate%"
plink.exe -ssh -l %2 -pw %3 -batch "%1" -m "%actionfile%" >> "%LOGFILE%%separate%"
cscript //NOLOGO convertunix2dos.vbs "%LOGFILE%%separate%"
goto :EOF


:ERRORLINE
Echo ERROR: next line (something missing)
Echo %1;%2;%3
goto :EOF

:ERRORFILE
Echo ERROR: file %inputfile% does not exist in %CURDIR% directory
goto :EOF

:ERRORFILE2
Echo ERROR: file %actionfile% does not exist in %CURDIR% directory
goto :EOF

:ERRFILEPLINK
Echo ERROR: file plink.exe does not exist in %CURDIR% directory
Echo Execute plink.exe before executing this file
goto :EOF

:ERRFILEPLINKREG
Echo ERROR: file plink.reg does not exist in %CURDIR% directory
Echo Execute plink_reg.cmd before executing this file
goto :EOF

:ERRORNOFILE
Echo ERROR You must specify a filename containing line with these informations
Echo ip_or_name;login;password
Echo Ex: run
Echo %FILENAME% myOA.txt
Echo with myOAVC.txt containing
Echo 192.168.1.251;Administrator;password
Echo 192.168.1.252;Administrator;password
echo.
goto :EOF



For information, this script use convertunix2dos.vbs to convert unix OA or VC return carriage to windows (script found on the net, don't remember where, sorry for the author)

Dim fso, ts, s, arg, fil, fpath, s1
Set fso = CreateObject("Scripting.FileSystemObject")
arg = WScript.arguments.item(0)
Set ts = fso.OpenTextFile(arg, 1, False)
s = ts.ReadAll
ts.Close
Set ts = Nothing

s1 = Replace(s, vbCrLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbCr, vbCrLf, 1, -1, 0)

Set ts = fso.CreateTextFile(arg, True)
ts.Write s1
ts.Close
Set ts = Nothing
Set fso = Nothing