後來覺得作業系統的專武,其實早有一個正式名稱,叫CLI,如jboss-cli、redis-cli等,Windows的CLI雖然是PowerShell,但仍保留支援前一版的CLI:DOS Script。而在系統在客戶端或公司VM的主機行之有年,年紀可能都能念國中、高中了,不支援太新版的PowerShell,DOS Script還是能加減用。
以下是當初幫客戶寫的過版Tableau的Script,需要輸入Tableau帳密及DB的密碼再進行過版。
@echo off
SetLocal EnableExtensions EnableDelayedExpansion
set /p id="Input TABLEAU Account:"
set /p pwd="Input TABLEAU Password:" < Nul
call :PasswordInput
set /p pwd="Input DB Password:" < Nul
call :PasswordInput2
for %%a in (F:\publish\*) do (
set filename=%%a
echo !filename!
set tt=!filename:~11,-4!
echo !tt!
del !tt!.log
"F:\Tableau\Tableau Server\10.5\bin\tabcmd" publish !filename! -n !tt! -s http://127.0.0.1:8000 --username %id% --password !LINE! --db-username RPTUser --db-password !LINE2! --project "RPTPRJ" --save-db-password --save-oauth --overwrite --tabbed 2>!tt!.log
call :filesize ".\!tt!.log"
rem echo !size!
if !size! GTR 0 (
echo Deploy Error
goto :Eof
)
)
Goto :Eof
:PasswordInput
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401.
::Set in variable Line a input password
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line="
:_PasswordInput_Kbd
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&Goto :Eof
If !CHR!==!BS! (If Defined Line (Set /P "=!BS! !BS!" <Nul
Set "Line=!Line:~0,-1!"
)
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line=!Line!^!"
) Else Set "Line=!Line!!CHR!"
)
Goto :_PasswordInput_Kbd
:PasswordInput2
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401.
::Set in variable Line2 a input password
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line2="
:_PasswordInput_Kbd2
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&Goto :Eof
If !CHR!==!BS! (If Defined Line2 (Set /P "=!BS! !BS!" <Nul
Set "Line2=!Line2:~0,-1!"
)
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line2=!Line2!^!"
) Else Set "Line2=!Line2!!CHR!"
)
Goto :_PasswordInput_Kbd2
:: set filesize of 1st argument in %size% variable, and return
:filesize
set size=%~z1
exit /b 0