Solved

Script to reboot Dlick DGS-1210-10P Switch

Posted on 2013-06-21
37
790 Views
Last Modified: 2013-09-01
Hello Folks,

I would like to set up script which executes with a scheduled task on a client's server to reboot a Dlick DGS-1210-10P Switch once a week. Does anyone have a script that might work for this? Thanks!
0
Comment
Question by:JohnnyD74
  • 20
  • 17
37 Comments
 
LVL 76

Expert Comment

by:arnold
Comment Utility
The first thing why would you think you need to reboot the switch on such a schedule?
If the switch hangs on this scheule, I think it suggests that you have misconfigured interfaces that cause Crc errors.  Check the switch for te errors and or react them.
I.e. you have switch port set to 1000 FDX, while the system that is connected to it is left at auto negotiate and vice versa.

A script is fairly easy to write depending on the interface
Telnet, ssh or web based access?

Do you have a scheduled task that reboots servers, routers, phones, on a regular basis?

While the weekly reboot may work in restoring functionality, the issue might lead to the switch's early failure.
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hello Arnold,

I want to reboot the switch once a week because it is providing POE power to  a wireless network which I want to reboot 1X weekly for reliability as it is heavily used.  I have tried to write a script but is is actually NOT easy to get it to work with this device which is why I am asking or help here :)
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
To manage a wireless network to avoid running out of IPs, you would control the DHCP lease times. I.e. have a lower lease time of 3600 seconds.


What is the interface to the device?
What systems are available to you on which or from which a script will run?
0
 

Author Comment

by:JohnnyD74
Comment Utility
Thanks:) I don't currently have any DHCP lease issues. The protol is Telnet. I only need help creating a script...I can set up the rest.
0
 

Author Comment

by:JohnnyD74
Comment Utility
The interface is Ethernet
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
What systems do you have on which to create a script?
Linux/windows?
Perl/activeperl with Net::Telnet module is a fairly simple way to create a script that will establish a telnet connection and the run a command.

Just curious, what is the issue that you see that requires the weekly reboot?

Please note that the poe power load is highest right after the reboot as all connected devices start to draw power at the same time.

A scheduled reboot only masks the real issue that could rear its ugly head at the most inconvenient time.

Defining the problem and then resolving it once and for all would be my approach.
0
 

Author Comment

by:JohnnyD74
Comment Utility
Oh....I see what you mean. I have windows systems. We are running 2 VLANS on the wireless network and occationally for some reason, one of the VLANS (guest VLAN) stop working and some users on that VLAN cannot access the internet. Only some users are affected (primarly small devices like iPads) This only happens every 4-6 weeks and a reboot fixes the problem.

I agree with you about masking the issue but I think this one would be very hard to solve given the nature of the beast. My hunch is that is it just a software bug.

I have researched scripts for this purpose but was not able to come up one that works.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
does each VLAN have its own DHCP server? Or do you have a super scope and a DHCP relay agent/helper on the VLAN that relays the DHCP requests to the DHCP server?
Check the DHCP server to make sure that when the issue occurs it is not an issue with running out of IPs. Check the ARP caching table.


Do you have active perl http://www.activestate.com/activeperl.
It is fairly simple to use
http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm

If you prefer powershell/vbscript
http://stackoverflow.com/questions/2634017/automating-telnet-with-powershell
http://www.toms-blog.com/PowerShell-emulate-telnet-session-and-test-output/
0
 

Author Comment

by:JohnnyD74
Comment Utility
Thanks again:) Yes...each VLAN has it's own DHCP server. I don't think I am running out but will check that. I am not a scripting expert and would probably need help with the script. Perhaps this is not the correct forum for this. Do you know where I might hire someone to help me?
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
The perl (more) and powershell scripts are "human" readable

See whether the perl example makes it clear.
The process is initiate a connection and wait for a response
username: login: not sure what the dlink response is.
use a telnet session and post the interaction (scrubing username)
0
 

Author Comment

by:JohnnyD74
Comment Utility
Great! Thank you. I need to leave now to install a new client but will update you with that info as soon as I can:)
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hello Arnold,

Sorry for the delay in getting back with you. I am finally able to come up for a little air from the install. Thanks again for your offer to help. This is what I currently get when I do a telnet session to the device. If I enter the command "reboot" at the promtp you see in the image, the device reboots:

Telnet session to switch
I did a seach on the internet for "switch script reboot" and came up with this. Could it be adapted?

Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "C:\Windows\System32\telnet.exe",,False
 
WScript.Sleep 2000
Do Until objTS.AtEndOfStream
     
    strName = objTS.ReadLine
    strComputer = "strname"
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
        ("Select * from Win32_PingStatus " & _
            "Where Address = '" & strName & "'")
     
    For Each objItem in colItems
 
            If objItem.StatusCode = 0 Then
 
            objShell.AppActivate "C:\Windows\System32\telnet.exe"            
                     
            WScript.Sleep 5000                
 
            objShell.SendKeys "o{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys strname & "{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "admin{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "12345{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "system{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "control{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "reboot{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "yes{ENTER}"
                WScript.Sleep 2000
            objShell.SendKeys "{ENTER}"
                WScript.Sleep 5000
     
        else
        end if
 
    next
Loop
 
    objShell.SendKeys "q{ENTER}"        
 
objTS.Close
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
I think so, you do not need the wmi section.

I have to look, I do not like the send info blindly which is done in this case.


Are you connecting to a single device, or do you need to go through a list that is stored in a file?
0
 

Author Comment

by:JohnnyD74
Comment Utility
I am connecting to the single switch only. I agree that I don't need the WMI section
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hi Arnold,

I used your resource and came up with this script which works. What code should I insert to kill the cmd.exe process after the switch starts to reboot?

set oShell = CreateObject("WScript.Shell")
oShell.run "cmd.exe"
WScript.Sleep 1000
 
oShell.SendKeys"telnet 10.90.90.90"
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys"admin"
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys"password"
oShell.SendKeys("{Enter}")
 
oShell.SendKeys"reboot"
oShell.SendKeys("{Enter}")
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Use oshell.run "cmd.exe",0
Not sure why you are not starting telnet.exe directly versus running cmd.exe.
Instead of running telnet 90.90.
You would use open 90.90.

Or after reboot, sendkeys "exit{enter}"

set oShell = CreateObject("WScript.Shell") 
oShell.run "telnet.exe" 
WScript.Sleep 1000 
 
oShell.SendKeys"open 10.90.90.90" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 1000 
oShell.SendKeys"admin" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 1000
oShell.SendKeys"password"
oShell.SendKeys("{Enter}") 
 
oShell.SendKeys"reboot" 
oShell.SendKeys("{Enter}")
oShell.SendKeys"exit{Enter}"

Open in new window

0
 

Author Comment

by:JohnnyD74
Comment Utility
Thank you, Arnold. Your modification works fine but the CMD window still does not close.Is there an option to force quite the cmd.exe?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 76

Expert Comment

by:arnold
Comment Utility
Try instead of run cmd.exe which opens the window and requires the sendkeys exit.  I may have only had one that closed the telnet session within the command.

i.e. oShell.run "telnet 10.90.90.90"
when the session terminates so should the window.

There is an option to oShell.run "command",0
this will not make it visible, but may accumulate. Try using telnet directly and then if it does not work. use the ,0 option as well as add an additional
oShell.Sendkeys "exit{ENTER}"

this should close the command window.
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hi Arnold,

I am sorry for my terribly late replay. I have been working very late and have been having trouble finding time.

I tried inserting the: Shell.run "command",0 command but I get the error:

Line: 17
Char: 1
Error: The system cannot find fine file specified.

Thank you,

John
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Command was just a pace holder.
You would use "telnet 10.90.90.90",0
0
 

Author Comment

by:JohnnyD74
Comment Utility
"telnet 10.90.90.90" works without the "0". Does that mean that I don't need it?
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Yes. The ,0 option should be one that starts the command window minimized, but maybe not.
As soon as you close the telnet session, the window goes away.
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hi Arnold,

Sorry again for my late reply. I was out of town for a week. The script still does not close on it's own. Perhaps the best course of action is to have a scripting pro help me via remote support. Unless you have other suggestions, I will proceed with this route. Thank you very much for all your help.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Please Repost the entire script that you have.

I'll test its behavior and will post back comments/adjustments if any.
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hi Arnold,

Again...sorry for the delay. Here is whole script. Thank you!

set oShell = CreateObject("WScript.Shell")
oShell.run "telnet.exe"
WScript.Sleep 1000
 
oShell.SendKeys"open 10.90.90.90"
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys"admin"
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys"admin"
oShell.SendKeys("{Enter}")
 
oShell.SendKeys"reboot"
oShell.SendKeys("{Enter}")

oShell.run "command",0
oShell.SendKeys("{Enter}")
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Try the following:
set oShell = CreateObject("WScript.Shell") 
oShell.run "telnet.exe 10.90.90.90"
WScript.Sleep 1000 
 
oShell.SendKeys"admin" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 1000
oShell.SendKeys"admin"
oShell.SendKeys("{Enter}") 
 
oShell.SendKeys"reboot" 
oShell.SendKeys("{Enter}")

Open in new window

0
 

Author Comment

by:JohnnyD74
Comment Utility
Hello Arnold,

Thank you again for your help. I tried your new script but unfortunately, it does the same thing and sticks on the following screen indefinately after the reboot in initiated: http://screencast.com/t/BYG4pXMI
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
On reboot the dlink maintains a connection.
Try adding a two minute delay
 wscript.sleep 120000
oShell.sendkeys("quit{enter}")

Alternatively,
oShell.sendkeys ("^{[}")
Wscript.sleep 1000
oShell.sendkeys("quit")

This should equal issuing a ctrl+[ to interrupt the telnet session connection.

http://www.pctools.com/guides/scripting/detail/149/?act=reference
0
 

Author Comment

by:JohnnyD74
Comment Utility
Can you tell me where I should insert the wscript.sleep 120000 command?
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
At the end of the existing script.  This will deal with trying to close the session.
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hi Arnold,

Thank you again so much for your help. I tried putting the wscript.sleep 120000 command at the end of the script but it still stayed open after more than an hour of letting it sit. Sorry this it a tough one. Any other ideas?
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
You need to include the sendkeys quit instruction as the last option.
Dd you try the alternative?
0
 

Author Comment

by:JohnnyD74
Comment Utility
Hi Arnold,

I did do that. I included both the sleep and sendkeys commands.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Strange.  Often when a router reboots it terminates the telnet session.

Have to think.
0
 

Accepted Solution

by:
JohnnyD74 earned 0 total points
Comment Utility
Hi Arnold,

I have decided to simply use the script as it is without exiting. Thank you for all the help...sorry we could not come up with a solution but I am happy as it is. Thanks again!
0
 

Author Closing Comment

by:JohnnyD74
Comment Utility
We were not able to come up with a solution.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

743 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

16 Experts available now in Live!

Get 1:1 Help Now