Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Telnet Script

Status
Not open for further replies.

bcbm

Technical User
Sep 21, 2004
41
US
Does anybody know how to write a script that will open a telnet window. I have a script written that will check for alarms, but I can't get the script to open the telnet window to a single ip address.
 
Do you already have a script running that needs to dial a telnet connection or launch a separate window in telnet mode? If the former, you can use the connectmanual command with a command line looking like this:

connectmanual TELNET "ip address"

If the connection is in your Connection Directory, you can use dial TELNET "connection name" instead.

If you need to launch a separate window, the command to do that is:

menuselect PWMENU 327

aspect@aspectscripting.com
 
Thanks for the information, the connectmanual did work. I'm still having the same problem and I guess that it must be the equipment I'm working on.

I'm trying to write a script that will login and pull alarms out of a piece of equipment (there is about 70 total) and for some reason some of the equipment will be skipped, but I can still telnet in to it if I open another window. The thing that does not make sence is it not always the same ones.

Is there a way to check beside the $CARRIER == 1. I have id in each box that is different, could I use an if statement to check it ?
 
If you are expecting a unique string from each system, you could use the waitfor or when target command to look for that string. Be aware that the waitfor command will timeout and proceed to the next command after 30 seconds unless you specify an alternate timeout value at the end of the command, i.e. waitfor "string" 45.


aspect@aspectscripting.com
 
Knob, thanks for all the help. The script seems to be working. Is there a limit to the size of the scipt, as the script runs when it hits the 15th equipment is stops running and waits for about 30 secs then starts running again. I checked the pause command and I have it set to 0, any other ideas because at this point that is the only problem.
 
There should not be any limit that I am aware of. Where are you getting the connection information from, the Connection Directory, a text file, the script itself, etc?

aspect@aspectscripting.com
 
All the IP's are in the script because when I tried the connection directory the script would skip equipment. Here is an example of what my script looks like. Just figure this goes on for a total of 70 IP's.

proc main
set capture file "M13 & STS Mux.txt"
connectmanual TELNET "10.6.2.187"
pause 0
capture on
waitfor " Login: "
transmit "********^M"
waitfor " Password: "
transmit "*******^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> "
transmit "exit^M"
connectmanual TELNET "10.6.2.188"
pause 0
waitfor " Login: "
transmit "*******^M"
waitfor " Password: "
transmit "********^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> "
transmit "exit^M"
capture off
endproc
 
Also when I tried to use the connection directory the script would not always skip the same equipment so I'm thinking that the equipment did not respond correctly so that Procomm knew it had a connection or that the equipment closed the connection before the commands were sent.
 
Try adding these lines after all of the connectmanual commands:

while $DIALING
yield
endwhile

Also, change all of the waitfor " Login: " commands to be:

if waitfor " Login: "

and then add an endif command after all of the transmit "exit^M" commands.

The first change will have your script pause until the dial process is complete. The second will make that particular portion of code execute only if the Login: prompt was received.


aspect@aspectscripting.com
 
Knob,

Here is part of my script the first 2 ip's complete with out any problems, the 2 listed after are the ones that pause at the end. the script works fine until it gets to the last waitfor & transmit commands.

connectmanual TELNET "*.*.*.*"
while $DIALING
yield
endwhile
pause 0
capture on
waitfor " Login: "
transmit "***^M"
waitfor " Password: "
transmit "***^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> "
transmit "exit^M"
connectmanual TELNET "*.*.*.*"
while $DIALING
yield
endwhile
pause 0
waitfor " Login: "
transmit "*********^M"
waitfor " Password: "
transmit "********^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> "
transmit "exit^M"
connectmanual TELNET "*.*.*.*"
while $DIALING
yield
endwhile
pause 0
waitfor " Login: "
transmit "***^M"
waitfor " Password: "
transmit "***^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> " <--------Hangs Here For 1 min
transmit "exit^M"
connectmanual TELNET "*.*.*.*"
while $DIALING
yield
endwhile
pause 0
waitfor " Login: "
transmit "***^M"
waitfor " Password: "
transmit "***^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> " <---------Hangs Here For 1 mins
transmit "exit^M"
 
I noticed you have these two lines back to back in a few places in your script:

transmit "***^M"
transmit "Q^M"

You might try adding either a waitfor command (for the proper string) or a pause 1 between those commands to ensure that the second transmit command is not being sent before the system is ready for another command.


aspect@aspectscripting.com
 
Ok, same script different question. I would like to send the capture file by e-mail, I checked the sendfile command but the way I read the help file it looks like I can't send it that way. Is that correct, if not any ideas how I could do it ?
 
I have a couple different example scripts on my samples page that show how to send an email through Procomm. One way is to send through Outlook or another MAPI-compliant mailer on your system. The other way is to send an email using Procomm's mail client.


aspect@aspectscripting.com
 
Ok, I have tried the info on your site and by itself the e-mail works great, when I add it to the rest of my script I get an error window but no message. Please help this is the last step.

proc main
string sMailLogon = "ME" ;Mail logon/profile name
string sMailPassword = "" ;Not needed if using Exchange Server
string sTo = "ME; SOMEONE" ;Recipients as they appear in the Outlook address book or enter just email address
string sCC = "" ;CC recipients
string sBCC = "" ;BCC recipients
string sSubject = "CO Alarms Information" ;Subject of the message
string sContents = "" ;Points to a file containing the body of the email
string sAttach = "c:\log\M13 & STS Mux 1.txt" ;File(s) to attach to email
string sMailError ;Holds any returned errors
While 1
set capture file "M13 & STS Mux 1.txt"
while $DIALING
endwhile
pause 0
capture on
connectmanual TELNET "10.6.2.187"
pause 0
waitfor " Login: "
transmit "****^M"
waitfor " Password: "
transmit "****^M"
transmit "Q^M"
waitfor "> "
transmit "alarms^M"
waitfor "> "
transmit "exit^M"
capture off
mapisend sMailLogon sMailPassword sTo sCC sBCC sSubject FILE sContents sAttach sMailError
if success
usermsg "Email sent successfully" ;Email sent successfully
else
errormsg "%s" sMailError ;Display error message
endif
pause 5
endwhile
endproc
 
I noticed that you have this line in your script:

string sAttach = "c:\log\M13 & STS Mux 1.txt"

but you also have this line later:

set capture file "M13 & STS Mux 1.txt"

Unless you are using the set capture path command to use c:\log for your capture files, then your script will be trying to attached a (likely) non-existent file.

What error message was displayed when you ran the script?


aspect@aspectscripting.com
 
I do have the capture path set in the config of procomm, but I'll set it in the script also. the error message with just shows a ASPECT error with nothing in it. I know it's now much to go on, but I think that the problem is the order that the mapisend is in because if I use just the e-mail demo that I pulled off your site it does works, just not once I put it with the rest of my current script.
 
Knob,

Thanks for all the help, the script works great. The e-mail problem was beacuse I did not give a file name for the body of the message string, I had just left if empty.
 
if these are all the same type of gear, you may just want to read in the ip addresses from a flat text file or even a spreadsheet. keeps the script compact as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top