LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 09-15-2005, 07:01 AM   #1
ripcurl
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
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,341

Rep: Reputation: 73
Maybe try :
Code:
grep -rl e1 /home/configs | sed -e 's#.*/##' -e 's#.cnfg##' > list.txt
 
Old 09-15-2005, 07:55 AM   #3
hhamid
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

------------------------------

#!/bin/bash

PATHTOSEARCH="/home/configs"
TEXT="YOUR_TEXT_TO_SEARCH"
OUTPUTFILE="Result.txt"

if [ -e $PATHTOSEARCH/$OUTPUTFILE ]; then
rm -f $PATHTOSEARCH/$OUTPUTFILE
fi

for DIR in $PATHTOSEARCH/*
do
#Checking for the .cnfg file in router folder
if [ -e $DIR/$DIR.cnfg ]; then
grep $TEXT $DIR/$DIR.cnfg > /dev/null
if [ $? == 0 ]; then
echo ${DIR:2} >> $PATHTOSEARCH/$OUTPUTFILE
fi
fi
done
 
Old 09-15-2005, 09:19 AM   #4
ripcurl
LQ Newbie
 
Registered: Sep 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by keefaz
Maybe try :
Code:
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
ripcurl
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
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

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


Reply


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 12:13 PM.

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