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 10-31-2013, 07:48 PM
Junho Junho is offline
Registered User
 
Join Date: Oct 2013
Posts: 4
How can I Auto save log file?

This is my Daily System Check shell.

I want to save automatically to file.

The file name is "2013-11-01-Time-Min.txt" at c:\log

I studied many sample shell.. but hard to understand...

help me.

==============================================

Code:
# $language = "python"
# $interface = "1.0"

# Account for SERVER
ServerUserLoginID = 	"."
ServerUserLoginPW = 	"-"
ServerRootPW = 				"!"


# Account for Router
RTRloginID = 					""
RTRloginPW = 					"!"
RTRenablePW = 				"!"

# Account for Firewall-A L2
FWL2loginID =					""
FWL2loginPW =					"!"
FWL2enablePW = 				""

# Account for Firewall -B
FWloginID = 					""
FWloginPW = 					"!"



#############################################################################################
#----------------------- Share module for Server end ----------------------------------------------
def BigServer ():
  #Login
  crt.Screen.WaitForString("s password: ")
  crt.Screen.Send(ServerUserLoginPW + chr(13))
  crt.Screen.WaitForString(chr(126) + "]$ ")
  
  #su
  crt.Screen.Send("su" + chr(13))
  crt.Screen.WaitForString("Password: ")
  crt.Screen.Send(ServerRootPW + chr(13))
  crt.Screen.WaitForString("]# ")
  
  #command
  crt.Screen.Send("ls -la /home/scloud;" + chr(13))
  crt.Screen.WaitForString("]# ")
    
  crt.Screen.Send("cat /root/anaconda-ks.cfg" + chr(13))
  crt.Screen.WaitForString("]# ")

  crt.Screen.Send("cat /root/chef_bootstrap.sh" + chr(13))
  crt.Screen.WaitForString("]# ")

  crt.Screen.Send("cat /root/post_install.sh" + chr(13))
  crt.Screen.WaitForString("]# ")
    
  crt.Screen.Send("ifconfig -a" + chr(13))
  crt.Screen.WaitForString("]# ")
  
  crt.Screen.Send("cat /etc/sysconfig/network-scripts/ifcfg-bond0" + chr(13))
  crt.Screen.WaitForString("]# ")
    
  crt.Screen.Send("cat /etc/sysconfig/network-scripts/ifcfg-eth0" + chr(13))
  crt.Screen.WaitForString("]# ")
   

#----------------------- Share module for Server end ----------------------------------------------


##################### DO main ######################################
def Main():
 crt.Screen.Send("date" + chr(13))
 crt.Screen.WaitForString(chr(126) + "]$ ")

#################### Start Network System Check #####################

#====================== Router 1호기 ================================
crt.Screen.Send("telnet xx.xx.xx.51" + chr(13))
crt.Screen.WaitForString("Username: ")
crt.Screen.Send(RTRloginID + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(RTRloginPW + chr(13))
crt.Screen.Send("en" + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(RTRenablePW + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 0" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("show running-config" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 24" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("~]$ ")
#---------------------- Router 1호기 --------------------------------


#====================== Router 2호기 ================================
crt.Screen.Send("telnet xx.xx.xx.52" + chr(13))
crt.Screen.WaitForString("Username: ")
crt.Screen.Send(RTRloginID + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(RTRloginPW + chr(13))
crt.Screen.Send("en" + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(RTRenablePW + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 0" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("show running-config" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 24" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("~]$ ")
#---------------------- Router 1호기 --------------------------------




#====================== Firewall 1호기 ============================
crt.Screen.Send("ssh -p 22 sadmin@xx.xx.xx.53" + chr(13))

crt.Screen.WaitForString("password: ")
crt.Screen.Send(FWloginPW + chr(13))

crt.Screen.WaitForString("BD-PEK>")
crt.Screen.Send("show configuration | display set | no-more" + chr(13))

crt.Screen.WaitForString("BD-PEK>")
crt.Screen.Send("exit" + chr(13))

crt.Screen.WaitForString("~]$ ")
#---------------------- Firewall 1호기 ----------------------------

#====================== Firewall 2호기 ============================
crt.Screen.Send("ssh -p 22" + " " + FWloginID + "@xx.xx.xx.54" + chr(13))

crt.Screen.WaitForString("password: ")
crt.Screen.Send(FWloginPW + chr(13))

crt.Screen.WaitForString("BD-PEK>")
crt.Screen.Send("show configuration | display set | no-more" + chr(13))

crt.Screen.WaitForString("BD-PEK>")
crt.Screen.Send("exit" + chr(13))

crt.Screen.WaitForString("~]$ ")
#---------------------- Firewall 2호기 ----------------------------



#====================== Firewall L2 1호기 ============================
crt.Screen.Send("telnet xx.xx.xx.70" + chr(13))
crt.Screen.WaitForString("Username: ")
crt.Screen.Send(FWL2loginID + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(FWL2loginPW + chr(13))
crt.Screen.Send("en" + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(FWL2enablePW + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 0" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("show running-config" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 24" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("~]$ ")
#---------------------- Firewall L2 1호기 ----------------------------


#====================== Admin Switch 2 호기 ==========================
# HBMT 2호기가 Mon1 서버에서 접속이 안되서, SPCS-I 서버로 빠져서 장비 상태 확인
crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("~$ ")

crt.Screen.Send("ssh -p 22" + " " + HBMTloginID + "@xx.xx.xx.63" + chr(13))
crt.Screen.WaitForString("assword: ")
crt.Screen.Send(HBMTloginPW + chr(13))
crt.Screen.WaitForString("BD-PEK>")
crt.Screen.Send("en" + chr(13))
crt.Screen.WaitForString("assword: ")
crt.Screen.Send(HBMTenablePW + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 0" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("show running-config" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 24" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("~$ ")

crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.37" + chr(13))
crt.Screen.WaitForString("s password: ")
crt.Screen.Send(ServerUserLoginPW + chr(13))
crt.Screen.WaitForString(chr(126) + "]$ ")
#---------------------- Admin Switch 2 호기 --------------------------



 
#====================== Admin Aggregation ============================
crt.Screen.Send("ssh -p 22" + " " + HBMTloginID + "@xx.xx.xx.1" + chr(13))
crt.Screen.WaitForString("assword: ")
crt.Screen.Send(HBMTloginPW + chr(13))
crt.Screen.WaitForString("BD-PEK>")
crt.Screen.Send("en" + chr(13))
crt.Screen.WaitForString("Password: ")
crt.Screen.Send(HBMTenablePW + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 0" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("show running-config" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("ter leng 24" + chr(13))
crt.Screen.WaitForString("BD-PEK#")

crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("~]$ ")
#----------------------  Admin Aggregation----------------------------



#################### Start Server System Check #####################
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.101" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.102" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.103" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.104" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.105" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.106" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.107" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.108" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.109" + chr(13))
BigServer()
crt.Screen.Send("ssh -p 2022" + " " + ServerUserLoginID + "@xx.xx.xx.110" + chr(13))
BigServer()


crt.Screen.Send("echo ================================ fin ================================" + chr(13))

Main()

Last edited by rtb; 11-01-2013 at 12:12 PM.
Reply With Quote
  #2  
Old 11-01-2013, 12:24 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Junho,

Thanks for the question. I think I need more information to assist.

When do you want to start logging?

What do you want to log?

Do you want to use a static log file name, or do you want to have a log file name that will include a dynamic timestamp?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 11-03-2013, 10:44 PM
Junho Junho is offline
Registered User
 
Join Date: Oct 2013
Posts: 4
Smile

Tank you for replying.

Almost Every morning I doing scripting. ( When I entered my office. )

The purpose of this script..
Important file backup...( Ex. interface, kickstart file, routing table, ... )

I want... to...
- When I doing this script... the file name is YYYY-MM-DD-Time-Min-Sec.log

Help me...

You save my time...

Thank you very much!
Reply With Quote
  #4  
Old 11-04-2013, 02:35 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Junho,

It sounds like you want to just enabling logging in your script. You can do this using the LogUsingSessionOptions method of the Session object. For example:
Code:
crt.Session.LogUsingSessionOptions
This option assumes that you have defined a log file name for the session or the Default Session. Please see the graphic for defining a log file name.

Another option would be to set the log file name and then use it. For example (requires a connected session):
Code:
Set objConfig = crt.Session.Config
objConfig.SetOption "Log Filename", "C:\Users\<user>\Desktop\%Y-%M-%D-%h-%m-%s.log"
objConfig.Save
crt.Session.LogUsingSessionOptions
Is this helpful?
Attached Images
File Type: png Session Log File Name.png (51.3 KB, 319 views)
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 07-17-2018, 03:30 PM
dlong dlong is offline
Registered User
 
Join Date: Dec 2015
Posts: 14
Daily Log File?

I would like to find a script which stops logging a minute after midnight, saves the day's capture to a file, and starts a new log file capture. The filename would incorporate a date/time stamp. How do I manage a daily log file for a connection which is always open?
Reply With Quote
  #6  
Old 07-17-2018, 03:46 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,021
Hi dlong,

What version of SecureCRT are you using?

Do you have a log file configured for the session?

This option has been available since v6.2:

Changes in SecureCRT 6.2 (Beta 1) -- January 29, 2009
-----------------------------------------------------
New features:

  • Added an option to create a new log file at midnight, which can be used to do automatic log rotation.

You just have to, as shown in the UI (Terminal / Log File category of Session Options), include %D in the log file name.

There's a great video on our YouTube channel regarding log file name substitutions.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 07-17-2018, 04:07 PM
dlong dlong is offline
Registered User
 
Join Date: Dec 2015
Posts: 14
Thanks Brenda.

That looks like a great possibility. Unfortunately, the serial port outputs a report every hour, and maybe 10 seconds after the hour. Ideally I would want the midnight report for the 11 PM hour to be included in its own day's logfile. Is there a way to delay the daily log feature by a minute?

Last edited by dlong; 07-17-2018 at 04:22 PM.
Reply With Quote
  #8  
Old 07-18-2018, 09:40 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,021
Hi dlong,
Quote:
Is there a way to delay the daily log feature by a minute?
No, sorry, there isn't that I'm aware.

What version of SecureCRT are you using?

What OS is it installed on?

As far as a scripting solution, much of it is going to involve working with the OS to get time/date details. I don't think we have any examples I can provide at this time.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 07-18-2018, 10:12 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,021
Hi dlong,

I have added this thread to a feature request in our product enhancement database for an option to automatically rotate log files when they reach a certain size (or duration). Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #11259" in the subject line or use this form from the support page of our website.

I did find some sample code after all (if on Windows/can use VBScript) if you can bridge the gap from "logging at a specific time" into "interval between running the script".

However, note:
It's possible that the log file may not contain all the data received, since there is a window of time between when logging is stopped and re-started that might affect raw logging in particular.


Code:
#$language = "VBScript"
#$interface = "1.0"
' RotateLogFileAfterSpecifiedInterval.vbs
'
' 2017 January 3
' 
' Description: 
' This script illustrates rotating the log filename specified 
' in SecureCRT Session Options at a specified interval. 
'
' It expects day/timestamp substitution parameters 
' (%Y%M%D and %h%m%s) are presently configured in the 
' Terminal / Log File category of Session Options
'
' Demonstrates:
' How to use the logging interface of SecureCRT
'     
' Usage:
' In any session where you wish to rotate log files, 
' use the following substition parameters to create 
' unique log filenames:
'    %Y: 4-digit year (or %y: 2-digit year)     %h: hour     
'    %M: month                                  %m: minute
'    %D: day                                    %s: seconds
' 
' To make the log file unique enough to prevent overwriting, 
' %h%m%s is necessary at a minimum. If you have the built-in 
' 24-hour rotation option enabled (start new log at midnight) 
' in the session, %D is also required.
'
' The script will run until cancelled or the session is disconnected.
 
crt.Screen.Synchronous = False
nDefaultIntervalSeconds = 5
If crt.Arguments.Count > 0 Then
   strArg = crt.Arguments(0)
   If IsNumeric(strArg) and (strArg - Fix(strArg)) = 0 Then
       nDefaultIntervalSeconds = cInt(strArg)
   Else
       crt.Dialog.MessgeBox "Argument invalid, expected numeric integer " & _
           "for the interval (seconds)."
   End If
End If
 
Rotate
 
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Rotate()
 
   strCurrLogFile = crt.Session.Config.GetOption("Log Filename V2")
   If Not InStr(strCurrLogFile, "%s") > 0 Then
       crt.Dialog.MessageBox "This script expects substitution parameters used " & _
           "in the log filename." & vbcrlf & vbcrlf & _
           "Ideally, your log file should be configured to include %Y%M%D and " & _
           "%h%m%s substitutions in order to prevent overwriting prior log files."
       Exit Sub
   End If
 
   Do
       crt.Sleep nDefaultIntervalSeconds * 1000
       crt.Session.Log false
       crt.Session.LogUsingSessionOptions 
   Loop
 
End Sub
__________________
Thanks,
--Brenda

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


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 02:17 PM.