Solved

SSH Script Execution in Windows Batch

Posted on 2016-08-26
21
33 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
  • 11
  • 5
  • 5
21 Comments
 
LVL 37

Expert Comment

by:Gerwin Jansen
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 37

Expert Comment

by:Gerwin Jansen
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
 

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 37

Expert Comment

by:Gerwin Jansen
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 76

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 37

Expert Comment

by:Gerwin Jansen
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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 37

Expert Comment

by:Gerwin Jansen
ID: 41773104
And the output of the reboot ssh screen?
0
 
LVL 76

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 76

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 76

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 76

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now