View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 09-15-2005, 07:01 AM   #1
LQ Newbie
Registered: Sep 2005
Posts: 3

Rep: Reputation: 0
newbie help on small shell script

Hey all,

I've got a fair few router configs backed up to a directory on one of my unix hosts.
They are backed up to /home/configs/<router name>/<router name>.cnfg.

What i'am hoping for is a script that can create a list of routers that have a certain line in their config. eg (all routers with 'e1' in their configs)

I was thinking the logical steps i need to take are
1. create list of directorys in /home/configs directory
2. somehow create script to "cat /<router name>/<router name>.cnfg | grep e1" and then IF e1 exists in the config copy the routers name to a file.
3. contine until all the configs are finished, appending routers it finds with "e1" in the config to the file.

But i've got no idea how to actually archive this
Can anyone suggest a script to do this, or a better way of doing this?
Old 09-15-2005, 07:18 AM   #2
Senior Member
Registered: Mar 2004
Distribution: Slackware
Posts: 4,578

Rep: Reputation: 127Reputation: 127
Maybe try :
grep -rl e1 /home/configs | sed -e 's#.*/##' -e 's#.cnfg##' > list.txt
Old 09-15-2005, 07:55 AM   #3
LQ Newbie
Registered: Sep 2005
Location: California
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 0
I have written a good script for you;
I hope it is wath you want

Hamid Hajabdolali





#Checking for the .cnfg file in router folder
if [ -e $DIR/$DIR.cnfg ]; then
grep $TEXT $DIR/$DIR.cnfg > /dev/null
if [ $? == 0 ]; then
Old 09-15-2005, 09:19 AM   #4
LQ Newbie
Registered: Sep 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Originally posted by keefaz
Maybe try :
grep -rl e1 /home/configs | sed -e 's#.*/##' -e 's#.cnfg##' > list.txt
Thanks keefaz, that seems to work great in my Cywin testing.

I'll get back to you tomorrow and tell you how it goes.
Old 09-16-2005, 11:11 AM   #5
LQ Newbie
Registered: Sep 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Hey all,
I examined my records a bit more closely and the configs are actually recorded in txt files under the name of <router name>-confg

No file extensions, only the -confg at the end to indicate it's a router config.

How could i modify the script above to read these files?
"grep -rl e1 /home/configs | sed -e 's#.*/##' -e 's#.confg##' > list.txt"
Old 09-20-2005, 03:17 PM   #6
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 231Reputation: 231Reputation: 231
Change the '/home/configs' to '/home/configs/*-confg'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
small shell script required demigor Programming 6 08-08-2005 04:38 PM
Shell script newbie needs help! allididntwantto Programming 2 04-21-2005 05:53 AM
veprory simple but frustrating for a newbie shell script question marigb Linux - Newbie 11 04-28-2004 12:11 PM
shell script newbie question yoshi95 Programming 1 03-11-2004 02:43 AM

All times are GMT -5. The time now is 06:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration