Link to home
Start Free TrialLog in
Avatar of sdhonea
sdhoneaFlag for United States of America

asked on

SSH Script Execution in Windows Batch

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
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

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.
Avatar of sdhonea

ASKER

Result:

C:\Utility>plink -ssh admin@10.2.1.2 -pw xxxxxxx reboot
reboot: cannot open
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.
Avatar of sdhonea

ASKER

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
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
Avatar of sdhonea

ASKER

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
Avatar of sdhonea

ASKER

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
On the suggested path, look where reboot is

Plink -ssh admin@10.1.2.1 -pw xxxxxxxx 'nohup /bin/reboot'
Avatar of sdhonea

ASKER

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.
>> 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.
Avatar of sdhonea

ASKER

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...
And the output of the reboot ssh screen?
Where is your DHCP server? Check the duration of the cache/arp retention.

Any loging determination what causes this situations?
Avatar of sdhonea

ASKER

Do you think a longer lease would reduce the client drops?
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.
Avatar of sdhonea

ASKER

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.
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.
Avatar of sdhonea

ASKER

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
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sdhonea

ASKER

None of the suggestions resolved the issue.