Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I am running Cisco Netflow at linux box, Every 15 mints some NFC application is creating files at cisco folder. i.e file is like this "/opt/CSCOnfc/Data/LinuxNFC/2006_01_14/10.76.5.101/DetailCallRecord/10.76.5.101.0200"
. Here only 2006_01_14 directory will change and 10.76.5.101.0200 file name will change. If i have 400 routers it will generates 10.76.X.X directories also. After that file is generated i am executing one perl script to read that file. i.e "perl NetflowPP.pl -f /opt/CSCOnfc/Data/LinuxNFC/2006_01_14/10.76.5.101/DetailCallRecord/10.76.5.101.0200" to convert excel sheet.
so i wanted to write one shell script to read data in date directory, router directory and inside router directory router with time stamp file for perl script input file. Here 4 variables are there. pls help me to write a script or pls give me if somebody having already writen scripts.
regards
Ajay

Your description of what you want is confusing.
Are you executing the perl script 400 times, once for each of the routers?
Are you asking for a script that gets the path to each file and then iterates over that list executing the perl script for each file?
Instead of a separate shell script, it would be easy to have the perl script locate the files.

FishMonger,
Thanks for reply, Yes i am aksing one script that is shell or perl which will get the path for each file where my NFC is placed,.Ok we will write perl script only which will reads files from reqired directories, In my above post i explain i having one directory structure where NFC is creating or placing files with router ip address like 10.76.5.101 i.e /opt/CSCOnfc/Data/LinuxNFC/2006_01_14/10.76.5.101/DetailCallRecord/10.76.5.101.0200"
/opt/CSCOnfc/Data/LinuxNFC/2006_01_14/10.76.10.153/DetailCallRecord/10.76.10.153.0200"
/opt/CSCOnfc/Data/LinuxNFC/2006_01_14/10.76.15.141/DetailCallRecord/10.76.15.141.0200"
up to /opt/CSCOnfc/Data/LinuxNFC/ is static,
/10.76.15.141/DetailCallRecord/ is static (where i added router ip address to collect NFC info at NFC application)
2006_01_14 is dynamic (every day creates one directory under /opt/CSCOnfc/Data/LinuxNFC, if next day it will create 2006_01_15).
10.76.5.101.0200 is dynamic (every 15 mints, if creates then next file is 10.76.5.101.0215 ).Now after getting the file path from script i will pass this script out to my NetflowPP.pl file. Say you created fish.pl which is points to my directory file opt/CSCOnfc/Data/LinuxNFC/2006_01_14/10.76.5.101/DetailCallRecord/10.76.5.101.0200,
then i will execute NetflowPP.pl -f fish.pl ( -f is my input file).
In unix i have seen this command a=/opt/CSCOnfc/Data/LinuxNFC
b=`date '+%Y'"_"'%m'"_"'%d'`
cd $a/$b
pwd
then output is
/opt/CSCOnfc/Data/LinuxNFC/2006_01_14
so i ask for shell script, but i will write on perl only.
regards
Ajay

Since I don't have any of your files to preform the proper testing, this may or may not work, but give it a try.
This forum is a joke when posting code because it strips out all of the intendation.
#!/usr/bin/perl -w
use strict;
use POSIX qw(strftime);my $today = strftime("%Y_%m_%d", localtime);
my $basedir = "/opt/CSCOnfc/Data/LinuxNFC/$today";
my @routers = grep{-d $_}<$basedir/*>;foreach my $router (@routers) {
my $records = "$basedir/$router/DetailCallRecord";
my @files = <$records/$router.*>;
foreach my $file (@files) {
system("NetflowPP.pl -f $basedir/$router/DetailCallRecord/$file");
}
}

Actually, that's not going to work as expected. I forgot that the @routers array will hold the full path not just the filnal dirname (router IP). We need to remove the references to $basedir in the foreach loop.
See if this modified version works.
foreach my $router (@routers) {
my @files = <$router/DetailCallRecord/$router.*>;
foreach my $file (@files) {
system("NetflowPP.pl -f $router/DetailCallRecord/$file");
}
}

Oops, I think I did it again.
system("NetflowPP.pl -f $router/DetailCallRecord/$file");
should be
system("NetflowPP.pl -f $file");

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |