Command Prompt Response


gfd

Well-known member
Local time
7:04 AM
Posts
17
OS
Windows
Greetings,

I am trying to write a batch file which will use SSH to connect with a managed switch. Once connected, I would like to turn the POE on or off for a single port on the switch. Here is the command prompt routine. My input is in bold letters and RETURN is my use of the enter key:

C:\Users\goofy>plink admin@192.168.xx.xxx
Using username "admin".
Further authentication required
admin@192.168.xx.xxx's password: password

Access granted. Press Return to begin session.
RETURN

SX3206HPP>enable
RETURN

SX3206HPP#config
RETURN
SX3206HPP(config)#interface ten-gigabitEthernet 1/0/4
RETURN
SX3206HPP(config-if)#power inline supply enable
RETURN
SX3206HPP(config-if)#end
RETURN
SX3206HPP#exit
RETURN
SX3206HPP>exit
RETURN
C:\Users\goofy>

I would like to convert this to a batch file, where any required input is part of the batch file

I use several batch files, but I am new to networking and have never responded to a password with data typed in the batch file. Also, the use of the enter key is required several times. Thanks in advance for any help you can offer.

Graham

Windows 11 24H2 26100.3476
 

My Computer

System One

  • OS
    Windows
    Computer type
    PC/Desktop
    Manufacturer/Model
    ASRock/AMD
    CPU
    AMD 7950X
    Motherboard
    ASRock X670E Taichi
    Memory
    2 x 32GB G.Skill Flare X5 5600
    Graphics Card(s)
    Asus Tuff GTX 1660 Ti
    Sound Card
    Onboard Realtek USB Audio
    Monitor(s) Displays
    Asus VG289Q 28"
    Screen Resolution
    4K
    Hard Drives
    1 x Samsung 970 Evo Plus 1TB NVMe
    3 x Samsung 970 Evo Plus 2TB NVMe
    4 x 2TB SATA RAID10
    1 x External WD My Book 8TB
    PSU
    Seasonic 1000W Gold
    Case
    Fractal Design Meshify 2
    Cooling
    Arctic Liquid Freezer II 360mm, 5 x 120mm Noctua Redux
    Keyboard
    Logitech MX Keys
    Mouse
    Logitech MX Master 3S
    Internet Speed
    1Gb
    Browser
    Microsoft Edge
    Antivirus
    Microsoft Defender
While you could feed a sequence of ECHO lines piped through plink, just use plink's command-line options.
Code:
@echo off
plink.exe -ssh admin@192.168.0.0.1 -pw abc1234 -batch "enable; config; interface ten-gigabitEthernet 1/0/4; power inline supply enable; end; exit; exit"
 

My Computer

System One

  • OS
    Windows 7
  • Great Support
Reactions: gfd
Thanks Garlin,

I can't get past the first request for a carriage return. There are seven additional carriage returns. Any idea how I deal with that? Thanks
 

My Computer

System One

  • OS
    Windows
    Computer type
    PC/Desktop
    Manufacturer/Model
    ASRock/AMD
    CPU
    AMD 7950X
    Motherboard
    ASRock X670E Taichi
    Memory
    2 x 32GB G.Skill Flare X5 5600
    Graphics Card(s)
    Asus Tuff GTX 1660 Ti
    Sound Card
    Onboard Realtek USB Audio
    Monitor(s) Displays
    Asus VG289Q 28"
    Screen Resolution
    4K
    Hard Drives
    1 x Samsung 970 Evo Plus 1TB NVMe
    3 x Samsung 970 Evo Plus 2TB NVMe
    4 x 2TB SATA RAID10
    1 x External WD My Book 8TB
    PSU
    Seasonic 1000W Gold
    Case
    Fractal Design Meshify 2
    Cooling
    Arctic Liquid Freezer II 360mm, 5 x 120mm Noctua Redux
    Keyboard
    Logitech MX Keys
    Mouse
    Logitech MX Master 3S
    Internet Speed
    1Gb
    Browser
    Microsoft Edge
    Antivirus
    Microsoft Defender
I'm guessing this is a Cisco device, which is finicky about CR/LF?
There's an extra line after the last "exit", but this forum software likes to eat any trailing CR's in a quoted post.

commands.txt
Code:
enable

config

interface ten-gigabitEthernet 1/0/4

power inline supply enable

end

exit

exit
Code:
@echo off
plink.exe -ssh admin@192.168.0.0.1 -pw abc1234 < c:\path\to\commands.txt
 

My Computer

System One

  • OS
    Windows 7
  • Great Support
Reactions: gfd
Thanks again garlin,

I am a bit embarrassed. I didn't bother listing the model. It is a TP-Link switch. TL-SX3602HPP. My apologies
 

My Computer

System One

  • OS
    Windows
    Computer type
    PC/Desktop
    Manufacturer/Model
    ASRock/AMD
    CPU
    AMD 7950X
    Motherboard
    ASRock X670E Taichi
    Memory
    2 x 32GB G.Skill Flare X5 5600
    Graphics Card(s)
    Asus Tuff GTX 1660 Ti
    Sound Card
    Onboard Realtek USB Audio
    Monitor(s) Displays
    Asus VG289Q 28"
    Screen Resolution
    4K
    Hard Drives
    1 x Samsung 970 Evo Plus 1TB NVMe
    3 x Samsung 970 Evo Plus 2TB NVMe
    4 x 2TB SATA RAID10
    1 x External WD My Book 8TB
    PSU
    Seasonic 1000W Gold
    Case
    Fractal Design Meshify 2
    Cooling
    Arctic Liquid Freezer II 360mm, 5 x 120mm Noctua Redux
    Keyboard
    Logitech MX Keys
    Mouse
    Logitech MX Master 3S
    Internet Speed
    1Gb
    Browser
    Microsoft Edge
    Antivirus
    Microsoft Defender
Hi garlin,

This worked! Thank you so much. The routine ran and the device attached to port 4 turned on. Adding the command file did the trick. Here is the Output:

Looking up host "192.168.50.110" for SSH connection
Connecting to 192.168.50.110 port 22
We claim version: SSH-2.0-PuTTY_Release_0.83
Connected to 192.168.50.110 (from 192.168.50.187:50806)
Remote version: SSH-1.99-IPSSH-6.6.0
Using SSH protocol version 2
No GSSAPI security context available
Doing Diffie-Hellman key exchange using 4096-bit modulus and hash SHA-512 (unaccelerated) with standard group "group16"
Server also has ssh-dss host key, but we don't know it
Host key fingerprint is:
ssh-rsa 1024 SHA256:6axN9M10pB/8jUcmzZ0aA897z5n9ObiIaT/+NCbNlyk
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) inbound MAC algorithm
Using username "admin".
Further authentication required
Further authentication required
Sent password
Access granted
Opening main session channel
Opened main channel
Allocated pty
Started a shell/command

SX3206HPP>enable
Main session channel closed
Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 256
FATAL ERROR: Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 256
Press any key to continue . . .

Does this line (Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 256) indicate that I didn't end the session correctly? Last question, should this also work if I connect using the key file pair I have setup?

Thanks again,
Graham
 

My Computer

System One

  • OS
    Windows
    Computer type
    PC/Desktop
    Manufacturer/Model
    ASRock/AMD
    CPU
    AMD 7950X
    Motherboard
    ASRock X670E Taichi
    Memory
    2 x 32GB G.Skill Flare X5 5600
    Graphics Card(s)
    Asus Tuff GTX 1660 Ti
    Sound Card
    Onboard Realtek USB Audio
    Monitor(s) Displays
    Asus VG289Q 28"
    Screen Resolution
    4K
    Hard Drives
    1 x Samsung 970 Evo Plus 1TB NVMe
    3 x Samsung 970 Evo Plus 2TB NVMe
    4 x 2TB SATA RAID10
    1 x External WD My Book 8TB
    PSU
    Seasonic 1000W Gold
    Case
    Fractal Design Meshify 2
    Cooling
    Arctic Liquid Freezer II 360mm, 5 x 120mm Noctua Redux
    Keyboard
    Logitech MX Keys
    Mouse
    Logitech MX Master 3S
    Internet Speed
    1Gb
    Browser
    Microsoft Edge
    Antivirus
    Microsoft Defender
SX3206HPP>enable
Main session channel closed
Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 256
FATAL ERROR: Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 256
Press any key to continue . . .

Does this line (Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 256) indicate that I didn't end the session correctly? Last question, should this also work if I connect using the key file pair I have setup?

Thanks again,
Graham
It's probably annoyed you "hung up" the connection. I believe there's an "-i [key file]"
 

My Computer

System One

  • OS
    Windows 7
  • Like
Reactions: gfd
This also worked

(
echo enable
echo config
echo interface ten-gigabitEthernet 1/0/4
echo power inline supply disable
echo end
echo exit
echo exit
echo disconnect
) | plink -v 192.168.50.110 -l admin -pw f*********** -P 22
PAUSE
 

My Computer

System One

  • OS
    Windows
    Computer type
    PC/Desktop
    Manufacturer/Model
    ASRock/AMD
    CPU
    AMD 7950X
    Motherboard
    ASRock X670E Taichi
    Memory
    2 x 32GB G.Skill Flare X5 5600
    Graphics Card(s)
    Asus Tuff GTX 1660 Ti
    Sound Card
    Onboard Realtek USB Audio
    Monitor(s) Displays
    Asus VG289Q 28"
    Screen Resolution
    4K
    Hard Drives
    1 x Samsung 970 Evo Plus 1TB NVMe
    3 x Samsung 970 Evo Plus 2TB NVMe
    4 x 2TB SATA RAID10
    1 x External WD My Book 8TB
    PSU
    Seasonic 1000W Gold
    Case
    Fractal Design Meshify 2
    Cooling
    Arctic Liquid Freezer II 360mm, 5 x 120mm Noctua Redux
    Keyboard
    Logitech MX Keys
    Mouse
    Logitech MX Master 3S
    Internet Speed
    1Gb
    Browser
    Microsoft Edge
    Antivirus
    Microsoft Defender
That was going to be my original answer, but wasn't sure if the CR/LF was going to be a problem. Since UNIX/Linux-based devices (like many network boxes) don't always agree with Windows.
 

My Computer

System One

  • OS
    Windows 7
  • Like
Reactions: gfd

Latest Support Threads

Back
Top Bottom