NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


One off Administration and Testing Scripts Using Vi
Topic: Administration   Posted:2005-07-19
Printer Friendly: Print

spacerspacer
If you have a list of servers, you can use the substitution feature in vi to quickly turn that list into a test script. For instance, if I want to test a list of domains that looks like this:

domain1.com
domain2.com
domain3.com
domain4.com
domain5.com

I can insert text before and after the domain name. Here is the ping test I want to do:

[usr-1@srv-1 ~]$ ping -c 1 -n domain1.com | grep icmp
64 bytes from 69.57.130.27: icmp_seq=0 ttl=47 time=64.8 ms
[usr-1@srv-1 ~]$ 

Let's combine these two. Hit : and enter the substitute command below:

domain1.com
domain2.com
domain3.com
domain4.com
domain5.com
~                                                                               
~                                                                               
:%s/^/ping -c 1 -n /

The ^ marks the beginning of the line. Now we have:

ping -c 1 -n domain1.com
ping -c 1 -n domain2.com
ping -c 1 -n domain3.com
ping -c 1 -n domain4.com
ping -c 1 -n domain5.com
~                                                                               
~                                                                               
5 substitutions on 5 lines  

Now, let's substitute at the end of the line using the $ match:

ping -c 1 -n domain1.com
ping -c 1 -n domain2.com
ping -c 1 -n domain3.com
ping -c 1 -n domain4.com
ping -c 1 -n domain5.com
~                                                                               
~                                                                               
:%s/$/ | grep icmp/

We have our batch file / shell script:

ping -c 1 -n domain1.com | grep icmp 
ping -c 1 -n domain2.com | grep icmp 
ping -c 1 -n domain3.com | grep icmp 
ping -c 1 -n domain4.com | grep icmp 
ping -c 1 -n domain5.com | grep icmp 
~                                                                               
~                                                                               
5 substitutions on 5 lines  





Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS