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 04-06-2006, 09:55 AM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
Writing to external file

I'm working on scripting operations on a number of Cisco devices via PerlScript. I want to be able to execute scripts, analyse their output and write comments to an external file. The problem is that I don't seem to be able to write to an external file when I am connected. Here's a sample script which illustrates the problem:

# $language = "PerlScript"
# $interface = "1.0"
use strict;
our $crt;
open LOGFILE, ">>mylog.log" or die "Can't open error log";
print LOGFILE "Opened log.\n";
my $text = $crt->Dialog->Prompt("Enter text to write to log:", "Log Data", "", 0);
print LOGFILE $text;

If I run this script from SecureCRT while not connected to any device, it works fine. Both the "Opened log." statement and whatever I enter in the dialog is written to the file. However, if I run this same script while connected to a remote device (via SSH2 at least - I haven't tested other types of connections), nothing is written to the file. The file is created if it does not exist. The dialog box opens and accepts input. But the file, even after closing the connection and exiting SecureCRT, is empty. I've tried manually flushing the buffer via:

my $old_fh = select(LOGFILE);
$| = 1;
select($old_fh);

but to no effect. Suggestions or solutions greatly appreciated.
Reply With Quote
  #2  
Old 04-06-2006, 09:57 AM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
Version info

Forgot to include: I'm using SecureCRT version 4.0.9
Reply With Quote
  #3  
Old 04-10-2006, 07:39 AM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
No solution

Since no one appears to have a solution or suggestion for this problem, I'd appreciate a small bit of assistance. I'd be grateful if someone using version 4.x could run the sample script both connected and unconnected and confirm the behavior I'm seeing. Second, I'd appreciate someone running version 5.x to see whether the behavior would be corrected by an update to the latest version. Thanks in advance to anyone who can assist.
Reply With Quote
  #4  
Old 04-10-2006, 11:32 AM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
Hello Dan.

Do you happen to already be logging to the same file that
you are trying to log to in in the script?

If so, you might try turning off logging first before trying
to log to that file.

Does that work for you?

Thanks

JJH
Reply With Quote
  #5  
Old 04-10-2006, 01:37 PM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
Logging file

JJH,

No, this is not the same file that I'm logging to. Apologies if my choice of variable names was confusing. I've tried with logging to a different file turned on and logging turned off. If I'm connected to a remote site, I can't send output to an external file regardless of the status of SecureCRT logging.

thanks for the response, though.
Reply With Quote
  #6  
Old 04-10-2006, 05:59 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
Hi Dan.

Thanks for the clarification. It looks like we'll need to
try to replicate the problem.

Which perl engine are you using?

Have you tried any other scripting language?

JJH
Reply With Quote
  #7  
Old 04-11-2006, 10:25 AM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
Quote:
Originally Posted by jjh
Hi Dan.

Thanks for the clarification. It looks like we'll need to
try to replicate the problem.

Which perl engine are you using?
C:\WINDOWS|► perl -v

This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 21 registered patches, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Binary build 816 [255195] provided by ActiveState http://www.ActiveState.com
Built Mar 1 2006 18:00:52


Running WindowsXP.

Quote:
Have you tried any other scripting language?

JJH
I haven't to date. My script is heavily dependent on text processing, including regex's. I believe MS has a downloadable option to add regex support to VBA but I'm not familiar with it, it's limits or capabilities. I'm using not just pattern matching but substitutions and transforms based on regexs and back references. I have little experience with Javascript. I'd really prefer to work in Perl if I can. I will try a VBScript test this afternoon, however, to try and isolate the problem as much as possible.

Last edited by dan.d.jones; 04-11-2006 at 12:18 PM.
Reply With Quote
  #8  
Old 04-11-2006, 02:40 PM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
Well duh!

Color me embarrased. While preparing to port my simple test script from Perl to VBA, I realized that I had not properly closed the file. I looked back in my actual script, where the problem first occurred, and I had not closed the file there either. I added a line to close the file to the script and the issue went away. Amazing what following proper programming procedure will do.
Reply With Quote
  #9  
Old 04-11-2006, 03:54 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
Hi Dan.

Thanks for letting me know. I'm glad you got things working
- even if you had to go through a little embarrassment to
get there.

If you have any other questions, please feel free to
contact us again.

Thanks

JJH
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 09:28 PM.