Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Creating a script for CLI based device admin

Creating a script for CLI based device admin

Creating a script for CLI based device admin


New to Python. I am working on learning the code, but I have a question to see what I am up against. I had written a few scripts in VBS that we use for automating device configurations, but unfortunately they won't work for the new guys that use MACs. The terminal software will only open Python scripts.

My goal is to pull data from a tab delimited text file, assign each field to an array variable and then insert that variable into a string that is pushed to the CLI prompt as it comes up. I know the following code is not correct, just trying to show my intent.



VSP9000(config#)> ip adress [ipaddress1]
VSP9000(config#)> ip mask [ipmask]
VSP9000(config#)> ip default-gateway [ipgatew]

I also want to recreate the ability to have the script access multiple lines of data from the text file and loop each time the series of commands is completed and then grab the next line from the text file. Any help or advice is greatly appreciated.

RE: Creating a script for CLI based device admin

Without writing the code I would suggest you investigate the CSV module {field delimiters are configurable so tab separation should not be an issue) and the os module
os.popen should enable you to execute commands at the command line level (no need to actual open a CLI.)

A Maintenance contract is essential, not a Luxury.
Do things on the cheap & it will cost you dear

RE: Creating a script for CLI based device admin

I think for an application this simple, you don't really gain anything from using the CSV module. Look at the "split()" built-in function, particularly, "split("\t")". Also, in Python, unless you use a heavy math adjunct like "numpy" or "scipy", there aren't any array's per se. Python uses lists, tuples, and more generally, "sequences". The only real difference for your application is that the indices are square bracketed: "[i]". So when you read a line from your text file, first you would get a string and strip off the linefeed:

CODE -->

for line in <file object name>:
Then you would make a list by splitting on the tabs:

CODE -->


Now, if you have a list of values of some particular field, you append a new value to that list:

CODE -->


Bob Rashkin

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close