Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-23-2011, 11:28 AM
KentC KentC is offline
Registered User
 
Join Date: Dec 2011
Posts: 5
Exclamation Need Help: Writing First Script for Linux Server Login And Data Logging

edit
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit

Last edited by KentC; 05-03-2012 at 11:18 AM.
Reply With Quote
  #2  
Old 12-23-2011, 12:13 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hello KentC,

Most of what you're wanting to do could be done without any scripts. Sending e-mail upon detection of some error condition will require a script.

For security reasons you may not want to embed a username and password in a script. SecureCRT's Session Options / Connection / Logon Actions provides Expect / Send capabilities. Using Expect/Send in Logon Actions allows you to hide the string you're sending (so your password doesn't need to sit in plain text in your script). If username and password are session specific, it makes sense to use Logon Actions for the session logon credentials. If you have the same username and password for all sessions and you don't care about security, it might be alright to leave the username and password in a script.

When learning how to script with SecureCRT, it's a good idea to use the Script Recorder in the Script menu. It will help show the general sequence you should use: WaitForString, Send, WaitForString, Send. Always use WaitForString before Send (whenever you see two back-to-back Sends, you are almost certainly looking at a problem). Failure to WaitForString before issuing Send is by far the most common mistake you'll find discussed in our Scripting forums.

Can you take a look at Logon Actions and see if the Expect/Send strings will be useful for you, at least for automating the logon process?

Next, can you try the Script Recorder and manually walk through the steps you want to take (issue the commands, such as show clock, show call...), and when you're finished running the commands select Script / Stop Recording Script and see how much of the script the Script Recorder can write for you?

In this case, looking for errors and sending e-mail should probably be added later, after you have a functioning script.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 12-23-2011, 03:12 PM
KentC KentC is offline
Registered User
 
Join Date: Dec 2011
Posts: 5
MikeD,

Thank you for your fast response!

I'll test what you've requested and post back with the results and what else I'll need to include to automate this work project.

Kent C.

Last edited by bgagnon; 12-23-2011 at 03:17 PM. Reason: Removed blank lines
Reply With Quote
  #4  
Old 12-23-2011, 04:44 PM
KentC KentC is offline
Registered User
 
Join Date: Dec 2011
Posts: 5
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit
edit

Last edited by KentC; 05-03-2012 at 11:20 AM.
Reply With Quote
  #5  
Old 12-24-2011, 09:21 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hi Kent,

Looks good! I'm glad you decided to use the Logon Actions, plus a script. Hiding passwords in the Logon Actions rather than placing them directly in the script seems like a best practice.

In your script, if you have three different machines then you'll probably need to change the WaitForString line from:
crt.Screen.WaitForString "lax-sta4-gw1-as5300#"
to something more general:
crt.Screen.WaitForString "#"

Another method which is very robust and reusable is to let the script detect the prompt (heuristically). If output from commands ends up containing the only non-unique part of all three prompts (e.g. '#') then this will be particularly important. The SecureCRT VBScript Scripting Manual has an example of heuristic prompt detection (see Section 7.2, page 92), and a lot of information and examples that I think you would appreciate.
Quote:
i would like to know at this point, how to create a different log for every 15 minute session instead of it continuing to record in the same logfile.
You could do it through scripting, with a timer and a function call to stop logging. However, I believe an even better approach for you will be to use the built in logging, because it sounds like you just want to connect to these three hosts every 15 minutes, run the command, log output to separate log files, parse output for errors and send e-mail notification, then disconnect.

In the Logging category you're already using variables for the log file name. I think you should add %m for minutes. Other variables you can use are listed in the Help file's Terminal/Log File section, in the Contents tab / Dialogs / Session Options Dialog / Terminal category. Using %m will help give a unique filename. All that's left is to automate the connection... see below.

Quote:
how this can be automated every 15 minutes for 3 separate tabs in one secureCRT window using this method.
A third party task scheduling process seems like it could be a good fit for this. Create a simple batch file or script which runs SecureCRT, then schedule that batch file or script to run every 15 minutes. (Your SecureCRT login script will take care of logging off and closing the program.)

You might use the Windows Task Scheduler, or schtasks, or the at command. You could also write a short script to kick it off. Look here for some script, schtasks, and at ideas. Here is an article specifically about using Task Scheduler to schedule a task every 15 minutes.

If you used a batch file to start SecureCRT, you could use a one-liner, like this:
"C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe" /T /S "Session 1" /S "Session 2" /S "Session 3"

Quote:
how can an email alert be added and it put some kind of numeric numbering for the errors if any are found?
You can use a CDO object to send e-mail. If you search for SecureCRT and CDO Object on the Internet you will find some links, such as this VanDyke SendEmail example, or this VanDyke Forum post. I can probably also provide more specific details in this thread, but first I think we need to know how to get the data that you want to send in e-mail.

How do you find the errors that you want sent in e-mail notification?
  • What condition indicates errors (e.g.: some command output says "err")?
  • Assuming it's command output, strings, which indicate error conditions, will you see these strings after each command, such as show clock, show cla1, etc.?
  • Do you want to parse within SecureCRT, or could you run a separate script to parse the log file later?
If you want to look for error-condition indicators in the output, I think a separate script that parses the information and sends e-mail could be the easiest to implement, augment, and maintain. The CDO object could still be used to send notification. Looking forward to your response!
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #6  
Old 12-26-2011, 05:24 PM
KentC KentC is offline
Registered User
 
Join Date: Dec 2011
Posts: 5
editeditediteditediteditediteditediteditediteditediteditediteditediteditediteditediteditediteditedit editeditediteditediteditediteditediteditediteditediteditedit

Last edited by KentC; 05-03-2012 at 11:21 AM. Reason: edit
Reply With Quote
  #7  
Old 12-27-2011, 08:55 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,886
Hi Kent,

Mike is out this week, but a colleague and I looked over the prior information in the thread.

We noticed you are using Windows 7 (64-bit) and we think the SendEmail tip is outdated and likely only works on Windows XP.

I have attached a newer version of that example script I think will be useful.
Attached Files
File Type: txt SendEmail.vbs.txt (6.9 KB, 649 views)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #8  
Old 12-28-2011, 09:01 PM
KentC KentC is offline
Registered User
 
Join Date: Dec 2011
Posts: 5
editeditediteditediteditediteditediteditediteditediteditediteditediteditediteditediteditediteditedit editediteditediteditediteditediteditediteditediteditedit

Last edited by KentC; 05-03-2012 at 11:21 AM. Reason: made email and smtp more generic
Reply With Quote
  #9  
Old 12-29-2011, 09:26 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,886
Hello Kent,

I do not know the specifics of your script(s) well enough at this point to provide advice.

First, you would simply want to make sure you can get the SendEmail example to work alone, then you can work on incorporating that functionality into the script(s) in progress.

After changing SMTP server and port and the From/To addresses in the example script, were you able to send/receive a notification e-mail?

I have not addressed parsing the logged data because debugging CDO object issues and parsing the logged data is getting a bit outside the scope of SecureCRT.

So I might get a sense of your efforts to date, could you send log file(s) and copies of the scripts to support@vandyke.com?

Please include "Attn Brenda - Forum Thread #10172" in the subject line.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
error , logon , vbscript


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:48 PM.