0

I frequently need to connect to various servers using SSH. I use the built-in SSH client from Cmder, like that :

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

But I'm lazy, hence I want to write a batch script that will take just one argument to connect to any SSH endpoint (eg: conssh root@server1), and will be called to create new ConEmu tabs from the New console dialog (creating as many ConEmu tasks as server is not an option).

conssh.bat (within %PATH%) :

@echo off

:: Aliases
if "%1"=="s1" (
    set arg="root@server1"
) else if "%1"=="c1" (
    set arg="-t root@server1 ssh root@container1.lxc"
) 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

How can I make it works (open only one tab, with the right icon, palette and title) ?

Thanks

  • Where Gabe you installed ConEmu? Try first variant with -new_console, but use ConEmuC.exe -c instead of cmd /c. – Maximus Jul 20 '17 at 23:36
  • I got the same result with ConEmuC.exe -c ... : useless tab with ExitCode=121. I use ConEmuC build 160710 x86 on Windows 7 64bit. – Vince Jul 20 '17 at 23:50
0

I answer my own question, found a workaround using ConEmu -Single (the script is run directly from the windows shell instead of the New console dialog) :

@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 root@container1.lxc
) 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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.