Please forgive me if things here sound abnormal, I don't know Perl at all. I DO know that it is a very valuable tool for automating routine tasks such as logging into routers and making changes (password management, certain stat collecting network-wide ie. IOS version info/ errors, et al.)
1. Are there any Perl scripts available for download. 2. Is there a good reference website for Perl beginners? 3. Is there a version of Perl that runs on Windows?
A scapegoat is often as welcome as a solution...never memorize what you can look up.
Perl is great for network admins, you can do almost anything with it. If you have specific questions/projects then post them up so we can all have a chew on them for you.
If you are just getting started I suggest you build up a personal library of little routines. For example, write one to ping a node and set a flag if it responds. Then produce one to map a network drive, release a network drive, open and maintain a log file and so on. These will give you lots of hands-on practice while still producing something more useful than "hello world". And when you have a 'real' project to do you can re-use them
I am also new to perl and am currently doing some self teaching. One thing I am currently working on is I am trying to create a script that will examine a txt file ( in this case the job details a ciscoworks job) to find the word failed and print the line containing that word. Any thoughts? Thanks in advance.
Well, that's simple, you just need to do the following in your script:
- have the details (filename) of the file you want to open "hardcoded" or provide a way for the user to input them at the runtime.
- loop through the text line by line, checking if your specific string "failed" is contained in each line. The full content of each line will be kept temporarilly in variable $line. You can also increment an $n integer variable to keep count of the line processed.
- in case your string-checking function returns true for a line, print whatever you want, i.e. the value of the $n and the value of $line.
- close the file
- add "sauce goodies", like colorizing your output, or adding any additional features you can think of.
That's the logical part, that should always be your fist step, as it will save you time. You do not need to plan ahead the "sauce goodies" or the additional features, unless they are major and for some reason affect the basic features. But for the first step, only design the basic features of your program too keep track easier, and the rest will fit in later.
The coding part is an other story, a bit frustrating, but only at first. It requires you to find and experiment with a number of language specific constructs (loops, statements, functions, variables, operators, etc), untill you get familiar with them and their syntax -in this particular case i.e., learn how to struct a "for" loop and an "if" statement, explore and experiment with several string and file related functions till you find the ones that suit your purpose, also see how to use variables to store various types of data and how to use operators to perform mathematical operations, like the +1 increment to the $n variable.
Each time make sure you are capable of combining what you have learned in different ways, and imagine how they could be applied for different uses, before you proceed in learning more complicate things. The best way is to always look for things as soon as you find them ahead of you, this way you remember them easier and comprehend them in practice. Finally, even if you don't understand fully a script, it can be helpful in many cases to just look at it's structure to get many quick answers.