Archive

Posts Tagged ‘tips’

Cisco IOS Tips – cache running-configuration

October 14th, 2009 Ali Abbas 1 comment

This is probably one of the most ignored and forgotten feature of IOS since 12.2(25)S and 12.2(27)SBC.

I am positing it  here as I never stopped coming across routers and switches with this feature not active. Please note you need to enough memory,to use this feature; that is to say, the available space in memory to hold a copy of the interfaces configuration.

As you may guess, a router or switch with a monstrous configuration, can take a while to display the running configuration when issuing

edge1#sh run

as it needs to fetch all the configuration from various places in memory.

Quoting Cisco

When invoked, NVGEN queries each system component and each instance of interface or other configuration objects. A running configuration file is constructed as NVGEN traverses the system performing these queries.

To speed things up, IOS ships in with a feature called Configuration Generation Performance Enhancement , which caches the interfaces configurations, which in return speed up NVGEN.

Activate caching with

edge1(config)#parser config cache interface

and voilà.

Categories: Cisco, Networking

Create your own manpage

December 12th, 2008 Ali Abbas No comments

Those who know me, know that I usually tend to document every little hack, server modification, kernel update and events that I happened to correct, install, modify, hack or fix!

I mainly do this as to keep on being productive but as well as keeping other admins updated on the modification which happened on the server.

Having said that! Most of us find ourselves often in front of a console terminal and sometimes in need of a memory refresh… wether it is us who can’t remember how we fixed a specific problem or another system administration who wonders “why is this perl script here and what does it do”.

Now… one could either set a homepage, create a documentation (wiki) and say “check this url for further info”. Considering that this is a cool alternative, it gets trickier when you are sitting in the server room with only the holy black console. Your server could have no connectivity, thus paralyzing you to fetch any remote documentation.

Many reasons, why manpages are cool tricks and since we are cool people! why not.

Now, let’s imagine I have a bash/perl script called “MysqlNas”.. this script does one thing and this thing is to backup through a cron, the server’s mysql table unto a NAS.

Now let’s create a manpage for our script, so that anyone who types “man mysqlnas” will get a rich set of infos / warnings / update version OR even server hacks we had to do, to make the script work (well let’s imagine :) ).

We are going to use a free utiliy called txt2man… the utility can be downloaded from the FSF website at http://directory.fsf.org/project/txt2man/

txt2man is a shell script, so you will call it as in ./txt2man

Create a txt file which will contain your program infos


vi mysqlnas.txt

Then type in (adjust at your will) the following structure


NAME
mysqlnas - backup the mysql databased unto the nas server

SYNOPSIS
/usr/bin/mysqlnas.pl database_name

DESCRIPTION
MysqlNas is a cool perl script which will recursively backup every database in /var/lib/mysql

A command argument could be parsed to the script to backup a single database... no ARG will result in the backup of all databases

ENVIRONMENT

You need to run the script as root

BUGS

Yet to be discovered

AUTHOR

Ali Abbas (alouche07@gmail.com)

One saved.. run the following command


./txt2man -t Mysql2Nas -s 8 mysqlnas.txt > mysqlnas.man

And voila we have created our manapage :) … Now we need to move the mysqlnas.man page into the /usr/share/man/(language)/manX/ for our man command to locate it.

** (language) : correspond to your system’s language! in our case, it would be “en”
** (X): correspond to the manpage section… we have set “-s 8″, meaning we are create our manapage in section 8 of the manage sections (for more info, refer to Wikipedia Manapage Sections)

so


mv mysqlnas.man /usr/share/man/en/man8/

now type in your command line


man mysqlnas

enjoy :)

Categories: Unix / Linux

safe guard editor

October 29th, 2008 Ali Abbas No comments

If you are like me, or a very experienced admin, you will realize that while running servers in production, you are more likely prompt to modify configuration files on the fly.

Now, one advise I give to any junior administrator, is to first of all backup any files they wish to modify. Running the cp command before editing a file, could be an hassle, especially when we are in a hurry.

The following tip isn’t a Bash scripting lesson as you will see but merely a safe guard concept, every admin could adopt to prevent downtime and headaches :-) .

Here is a little bash script that I usually set up on servers whenever I am prompted to modify configuration files on the fly.

#!/bin/bash
stamp=$(date +%s)
/bin/cp $1 $1.$stamp
/bin/vi $1
echo "Would you like to delete $1.$stamp ?"
read choice
if [ "$choice" = "yes" ]; then
rm -f $1.$stamp
fi

As you can see the script is very basic and straight forward, whenever the script is called such as “./vis filenameA”, it will make a copy of filenameA to filenameA. + the number of elapsed seconds since 01/01/1970 … it then opens up the file in my favorite editor ‘vi’ and prompt me later on if I wish to delete the backup file…

Now, you could modify this file, add more check conditions, spice up things but the idea behind it, is to create the automatic backup of files when they are being edited.

Save this script in a file.. chmod +x thescript (let’s call it vis)

Move it into the /bin folder and create an alias (alias vi=”vis”)

There you go…from now on, whenever you edit a file, you shouldn’t fear if you make a mistake or delete any important variable options.

Cheers,

Categories: Unix / Linux

Delete empty files, older than x days

October 11th, 2008 Ali Abbas No comments

Q: How do I delete files that older than a certain amount of days and which are empty

A: find . -empty -type f -mmtime +X | xargs rm or for those fancing exec, use find . -empty -type f -mmtime +X -exec rm {}

** X must be replaced with the number of days

cheers,

Categories: Bash, Unix / Linux