Use um script em lote como tarefa ConEmu

0

Freqüentemente preciso me conectar a vários servidores usando o SSH. Eu uso o cliente SSH embutido do Cmder , assim:

cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe root@server1" -new_console:C:"C:\Apps\cmder-git\icons\cmder.ico" -new_console:P:^<Ubuntu^> -new_console:t:server1

Mas eu sou preguiçoso, por isso quero escrever um script em lote que terá apenas um argumento para conectar-se a qualquer ponto de extremidade SSH (por exemplo: conssh root@server1 ) e será chamado para criar novas guias ConEmu do Diálogo do novo console (criar tantas tarefas do ConEmu quanto o servidor não é uma opção).

conssh.bat (dentro de% PATH%):

@echo off

:: Aliases
if "%1"=="s1" (
    set arg="root@server1"
) else if "%1"=="c1" (
    set arg="-t root@server1 ssh [email protected]"
) else (
    set arg=%1
)

:: cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail (works, but opens a useless tab : "ConEmuC: Root process was alive less than 10 sec, ExitCode=121.")

:: cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -cur_console:C:C:\Apps\cmder-git\icons\cmder.ico -cur_console:P:^<Ubuntu^> -cur_console:t:"%1"
:: => Fail (ConEmuC: Root process was alive less than 10 sec, ExitCode=1.)

:: "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail (ConEmuC: Root process was alive less than 10 sec, ExitCode=1.)

:: cmd /k "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail (works, but opens a useless tab : "ConEmuC: Root process was alive less than 10 sec, ExitCode=121.")

:: cmd /k "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -cur_console:C:C:\Apps\cmder-git\icons\cmder.ico -cur_console:P:^<Ubuntu^> -cur_console:t:"%1"
:: => Fail (opens a cmd.exe shell, not ssh)

:: cmd /c -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%"
:: => Fail (opens a useless tab, with wrong icon)

:: start /b "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail

:: start /b "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -cur_console:C:C:\Apps\cmder-git\icons\cmder.ico -cur_console:P:^<Ubuntu^> -cur_console:t:"%1"
:: => Fail

Como posso fazer isso funcionar (abra apenas uma guia, com o ícone, a paleta e o título corretos)?

Obrigado

    
por Vince 21.07.2017 / 01:16

1 resposta

0

Eu respondo a minha própria pergunta, encontrei uma solução alternativa usando ConEmu -Single (o script é executado diretamente do shell do Windows em vez do Novo diálogo do console ):

@echo off

set cmderlocation=C:\Apps\cmder-git
set icon=cmder_blue.ico

:: Aliases
if "%1"=="s1" (
    set arg=root@server1
) else if "%1"=="c1" (
    set arg=-t root@server1 ssh [email protected]
) else (
    set arg=%*
    set icon=cmder_red.ico
)

"%cmderlocation%\vendor\conemu-maximus5\ConEmu.exe" -Single -run cmd /c "%cmderlocation%\vendor\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:"%cmderlocation%\icons\%icon%" -new_console:P:^<Ubuntu^> -new_console:t:"%1"
    
por 22.07.2017 / 14:54