Reputation: 11
I'm working on a Windows batch script that invokes plink to interact with a Linux-based virtual appliance. The goal is to send a command like set account name User1
and, in response, the server should prompt for the user's privilege level. I need to respond to this prompt by sending 0
as the privilege level.
However, I've encountered an issue. While the batch script successfully sends the set account name User1
command, it doesn't seem to handle the subsequent interaction with the server as expected. Specifically, when the server prompts for the privilege level, the batch script appears to interpret a blank space as input. Furthermore, even though I attempt to send 0
as the privilege level in response to the second prompt, the server doesn't seem to accept it. Strangely, the server prompts for the privilege level a third time as well.
I'm puzzled by this behavior. Has anyone else experienced a similar issue or have insights into what might be causing this behavior? I'd greatly appreciate any guidance or suggestions on how to ensure that the batch script correctly interacts with the server's prompts and sends the desired privilege level.
Here's a simplified version of the batch script I'm using:
@echo off
setlocal enabledelayedexpansion
set PLINK_PATH=C:\Putty
set SERVER=192.168.100.91
set USERNAME=platformadmin
set PASSWORD=plat123#
(
ping 127.0.0.1 -n 50 > nul
echo set account name user1
ping 127.0.0.1 -n 10 > nul
echo 0
) | "%PLINK_PATH%\plink.exe" -ssh %USERNAME%@%SERVER% -pw %PASSWORD%
pause
CMD output:
Using username "platformadmin".
Command Line Interface is starting up, please wait ...
Welcome to the Platform Command Line Interface
VMware Installation:
4 vCPU: Intel(R) Core(TM) i3-4005U CPU @ 1.70GHz
Disk 1: 110GB, Partitions aligned
8192 Mbytes RAM
admin:set account name user1
Privilege Levels are:
Ordinary - Level 0
Advanced - Level 1
Please enter the privilege level :
privilege level must be 0 or 1, please try again...
Please enter the privilege level :0
privilege level must be 0 or 1, please try again...
Please enter the privilege level :
privilege level must be 0 or 1, please try again...
Please enter the privilege level :
Any insights into why the server isn't accepting the privilege level, and why it seems to misinterpret the blank space on the first prompt, would be really helpful. Thanks in advance!
I am new to Windows bat scripting and developing this script to minimize the time it may take for multiple account creation. Could not do much.
Upvotes: 1
Views: 84
Reputation: 202504
I'd guess that the device cannot cope with Windows CRLF line endings produced by the batch file/echo
.
Try the Linux's CR only. I do not think it's possible with batch file. But PowerShell (even if executed from a batch file) can do that. See Wait between sending login and commands to serial port using Plink.
Upvotes: 0