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
Solved

Script to reboot Dlick DGS-1210-10P Switch

Posted on 2013-06-21
37
843 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 77

Expert Comment

by:arnold
ID: 39268187
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
ID: 39268206
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 77

Expert Comment

by:arnold
ID: 39268218
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:JohnnyD74
ID: 39268222
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
ID: 39268230
The interface is Ethernet
0
 
LVL 77

Expert Comment

by:arnold
ID: 39268237
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
ID: 39268245
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 77

Expert Comment

by:arnold
ID: 39268255
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
ID: 39268267
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 77

Expert Comment

by:arnold
ID: 39268282
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
ID: 39268298
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
ID: 39294261
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 77

Expert Comment

by:arnold
ID: 39295370
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
ID: 39295374
I am connecting to the single switch only. I agree that I don't need the WMI section
0
 
LVL 77

Expert Comment

by:arnold
ID: 39296100
0
 

Author Comment

by:JohnnyD74
ID: 39298046
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 77

Expert Comment

by:arnold
ID: 39298866
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
ID: 39301336
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
 
LVL 77

Expert Comment

by:arnold
ID: 39302164
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
ID: 39328671
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 77

Expert Comment

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

Author Comment

by:JohnnyD74
ID: 39328713
"telnet 10.90.90.90" works without the "0". Does that mean that I don't need it?
0
 
LVL 77

Expert Comment

by:arnold
ID: 39328717
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
ID: 39362763
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 77

Expert Comment

by:arnold
ID: 39362920
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
ID: 39384980
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 77

Expert Comment

by:arnold
ID: 39384993
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
ID: 39388214
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 77

Expert Comment

by:arnold
ID: 39388233
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
ID: 39390553
Can you tell me where I should insert the wscript.sleep 120000 command?
0
 
LVL 77

Expert Comment

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

Author Comment

by:JohnnyD74
ID: 39406369
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 77

Expert Comment

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

Author Comment

by:JohnnyD74
ID: 39415812
Hi Arnold,

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

Expert Comment

by:arnold
ID: 39415833
Strange.  Often when a router reboots it terminates the telnet session.

Have to think.
0
 

Accepted Solution

by:
JohnnyD74 earned 0 total points
ID: 39443104
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
ID: 39456059
We were not able to come up with a solution.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

I see many questions here on Experts Exchange regarding switch port configurations and trunks. This article is meant for beginners in the subject to help to get basic knowledge about Virtual Local Area Network (VLAN (http://en.wikipedia.org/wiki/Vir…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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.

861 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