Solved

SSH Script Execution in Windows Batch

Posted on 2016-08-26
21
46 Views
Last Modified: 2016-09-18
I have a HPE M330 OfficeConnect 802.11ac access point.  It needs to be rebooted periodically in order to run well.  

The easiest way to reboot the AP is to SSH in and issue the 'reboot' command.

I am able to connect via plink.exe to reach the shell and manually enter reboot, but when I try to pull the command from a text file, I get an error ": cannot open"  Ultimately, I want to create a batch file and run it as a scheduled task.  

Here's the command line:

plink -ssh admin@10.2.1.2 -pw xxxxxxx -m reboot.txt -v

reboot.txt contains reboot on a single line with a return at the end (created in notepad).

Here is the verbose output of the plink command line.  I'd appreciate any assistance.

C:\Utility>plink -ssh admin@10.2.1.2 -pw xxxxxxx -m reboot.txt -v
Looking up host "10.2.1.2"
Connecting to 10.2.1.2 port 22
Server version: SSH-2.0-dropbear_0.51
We believe remote version has SSH-2 channel request bug
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.67
Using Diffie-Hellman with standard group "group1"
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 1040 68:fa:ef:f2:76:35:af:5f:27:a6:db:21:b8:84:bb:b2
Initialised AES-256 CBC client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 CBC server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "admin".
Sent password
Access granted
Opening session as main channel
Opened main channel
Started a shell/command
reboot
: cannot open
Server sent command exit status 255
Disconnected: All channels closed
0
Comment
Question by:sdhonea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
  • 5
21 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41771826
Can you try putting the reboot command on the command line? Remove -m and everything after that and replace with the contents of your text file.
0
 

Author Comment

by:sdhonea
ID: 41771837
Result:

C:\Utility>plink -ssh admin@10.2.1.2 -pw xxxxxxx reboot
reboot: cannot open
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41771937
Very strange, works on my end to a Linux server from Windows. Can you try without the ssh and pw options?

Like this:

plink admin@10.2.1.2 reboot

It should ask for the password.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:sdhonea
ID: 41771949
This AP won't allow the connection as telnet, has to be SSH.  

C:\Utility>plink admin@10.2.1.2 reboot
FATAL ERROR: Network error: Connection refused

If I add back the -ssh and manually enter the pw, I still get
C:\Utility>plink -ssh admin@10.2.1.2 reboot
admin@10.2.1.2's password:
reboot: cannot open
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41771981
Do you know where the reboot command is on the printer? You may have to add the path to the command line, for example:

/usr/bin/reboot
0
 

Author Comment

by:sdhonea
ID: 41772174
The command is in /splashbin

I tried plink -ssh admin@10.2.1.2 -pw xxxxxxx /splashbin/reboot and got "Invalid command".

I tried plink -ssh admin@10.2.1.2 -pw xxxxxxx -m reboot.txt -v

and adding reboot to the text file (and also adding cd /splashbin then reboot to the text file) and I get

Started a shell/command
cd /splashbin
reboot
: cannot open
Server sent command exit status 255
Disconnected: All channels closed
0
 

Author Comment

by:sdhonea
ID: 41772216
I tried just executing simply ls /splashbin in the command file.  Still get this error.  It accepts the command fine if I just log in and issue it.

Opening session as main channel
Opened main channel
Started a shell/command
ls /splashbin
: cannot open
Server sent command exit status 255
Disconnected: All channels closed
0
 
LVL 78

Expert Comment

by:arnold
ID: 41772644
On the suggested path, look where reboot is

Plink -ssh admin@10.1.2.1 -pw xxxxxxxx 'nohup /bin/reboot'
0
 

Author Comment

by:sdhonea
ID: 41772966
reboot is in /splashbin

plink -ssh admin@10.2.1.2 -pw xxxxxxx 'nohup /splashbin/reboot'

gets this result:

'nohup /splashbin/reboot': cannot open

Thank you.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41772974
>> I am able to connect via plink.exe to reach the shell and manually enter reboot
Can you show us the output of the reboot command that you enter manually.

What is your product ID / do you have the latest firmware version? You should not have to reboot the device periodically, I never have to reboot my wireless access point.
0
 

Author Comment

by:sdhonea
ID: 41773098
HPE M330 OfficeConnect 802.11ac access point JL026A.  I have six of these all on the latest available firmware and they all start dropping clients after about two weeks of not being rebooted.

I agree that they shouldn't need to be rebooted...
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41773104
And the output of the reboot ssh screen?
0
 
LVL 78

Expert Comment

by:arnold
ID: 41773202
Where is your DHCP server? Check the duration of the cache/arp retention.

Any loging determination what causes this situations?
0
 

Author Comment

by:sdhonea
ID: 41773246
Do you think a longer lease would reduce the client drops?
0
 
LVL 78

Expert Comment

by:arnold
ID: 41773421
A shorter lease will prevent the issue where there are no more IPs to allocate because they have been allocated no the lease time has not expired.
0
 

Author Comment

by:sdhonea
ID: 41775271
The lease is set at 24 hours.  There's no issue with insufficient addresses.  These are very small offices.

This wouldn't even be an issue except that my users are connecting to a Citrix server and the connection needs to stay alive in order to prevent an interrupted session/having to log in all over again.

I'd prefer to focus on how to automate the reboot, if possible.
0
 
LVL 78

Expert Comment

by:arnold
ID: 41775284
What is the consequence of running
plink -ssh user@apstation -pw xxxxxxx '/bin/nohup /full/path/to/where/reboot/is'?
plink -ssh user@apstation -pw xxxxxxx -t '/bin/nohup /full/path/to/where/reboot/is'?

try adding the -t option.
0
 

Author Comment

by:sdhonea
ID: 41775300
nohup doesn't appear to be a supported command:
HP-WLAN-AP# find */*noh*
find: */*noh*: No such file or directory
Invalid command.

Running command without nohup:
plink -ssh admin@10.2.1.2 -pw xxxxxxx -t -v '/splashbin/reboot'

result:
Using username "admin".
Sent password
Access granted
Opening session as main channel
Opened main channel
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
'/splashbin/reboot': cannot open
Server sent command exit status 255
Disconnected: All channels closed
0
 
LVL 78

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 41775309
double check that reboot is in /splashbin and is not somewhere else.


See if you have a scheduler on the system. and configure an auto-reboot once a week.....

Checking with the vendor to determine what is causing the saturation.  Do the logs indicate anything?
Is your SSID display enabled or disabled?  Any option to disable if enabled to avoid attempted attacks?
lower the Lease time to 8 hours-12hours to see if that makes a difference.

if you login onto one that is having issues and run arp -d after running arp -a
does it fix anything?

Something is causing this issue, but it is not clear what.
0
 

Accepted Solution

by:
sdhonea earned 0 total points
ID: 41796540
Looks like it is an issue with the AP.  Going to reach out to Hewlett-Packard for assistance.  Thanks to all for your suggestions.
0
 

Author Closing Comment

by:sdhonea
ID: 41803570
None of the suggestions resolved the issue.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question