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 03-16-2012, 02:50 PM
_raindrop18 _raindrop18 is offline
Registered User
 
Join Date: Apr 2011
Posts: 32
open a file and write a text on specfic location

I have this text file and I want to insert a snmp community string on a file located on multiple devices
Code:
           : (system.sysName.0
                        :value (Unknown)
                )

  )
        :snmp_community (
                :read (public)
                :write ()
        )
so I want to insert " public" in the middle of parenthesis ()

is that possible to do with ScrureCRT, any insight highly appreciated.

Last edited by _raindrop18; 03-16-2012 at 03:17 PM.
Reply With Quote
  #2  
Old 03-16-2012, 03:46 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hello,

The way you've described your project it sounds like you have a local file and want to script the modification of files on remote devices based on information you find in this file, but perhaps I'm misunderstanding.

Can you provide a little more information about your project or goal?

Are you wanting to modify a file locally and then upload that file to the devices, or are you wanting to script an interaction with the devices?

What steps do you currently take to add public inside parenthesis and get the remote device to accept the information?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 03-17-2012, 11:51 AM
_raindrop18 _raindrop18 is offline
Registered User
 
Join Date: Apr 2011
Posts: 32
thanks for the response, let me give you some easy example and if i can figure out this i can do the rest. let say I have a file name. user.txt on remote devices and i want to add(append) more users on that file. so the new users list are on my local pc as (new_user.txt) so i want the script read this new users list and append to remote device users.txt file. if i can figure how how to do that I will try to figure out the rest. I just want some basics .
again my objective is to " read the new_user list and append them on current user.txt located on remote device"
content of new_user.txt example -
# Mary Doe
# John South
# Bob Smith
thank you so very much for you assistance.

Last edited by _raindrop18; 03-17-2012 at 12:10 PM.
Reply With Quote
  #4  
Old 03-19-2012, 09:25 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Reading the file locally should be pretty straight forward. There is an example in the SecureCRT Scripting Guide, in a section titled Read Data from Separate Files: Hosts, Commands,
which shows how to read data from local files and send data to the remote.

I think you'll probably need a combination of the ReadDataFromFile() function shown in that example, and you'll need to create a function or subroutine which appends the data to the text file.

How do you currently append the data to the file?

For example, can you use a command like:
"cat 'some data' >> file.txt"
or
"sed 's/()/(public)/g' file.txt"?
Or, do you need to manually edit a text file on the remote and have a script drive the editor to make the change?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #5  
Old 03-19-2012, 09:59 AM
_raindrop18 _raindrop18 is offline
Registered User
 
Join Date: Apr 2011
Posts: 32
Quote:
"sed 's/()/(public)/g' file.txt
will work to replace the string (public) since the remote devices are Unix based. but I can't do cat on the remote file since the file need to append is on my local machine which is XP. so ithat is the reason I want use SECcrt to be a middle man to work between my pc and remote devices. as I said i can't put any file on remote device. so the new_user.txt always stay on my pc. so my objective is SECcrt read from my pc local file to push the list to remote li unix based device.
is that make sense what i am saying? thanks much again
Reply With Quote
  #6  
Old 03-19-2012, 10:43 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Quote:
but I can't do cat on the remote file since the file need to append is on my local machine which is XP.
Would echo work?

You'll read in the file locally, but finding the easiest solution on the remote is the question. If you really only ever needed to replace () with (public) then the sed command might be enough. It sounds like you really need to append data. If you were to read in a line of data from the local file, then you could issue a command to echo that data and append it to the file.

The following section of code (from the SecureCRT Scripting Manual, pp. 92-93), shows how you would send data to the remote:

Code:
' Send each command to the remote system.
For Each strCommand in vCommands
' Exit the For..Next loop if our current command is empty... ' otherwise, we'll just be pressing the Enter key pointlessly. If Trim(strCommand) = "" Then Exit For crt.Screen.Send strCommand & vbcr ' Wait for the command to complete before moving on to ' the next command crt.Screen.WaitForString strPrompt
Next
If you can use "echo" to append data then I think you would could modify the strCommand variable to be something something like this:
Code:
'... Same code as snippet above crt.Screen.Send "echo " strCommand & " >> " & "file.txt" && vbcr ' Wait for the command to complete before moving on to ' the next command crt.Screen.WaitForString strPrompt
Next
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
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 01:16 PM.