Results 1 to 8 of 8
hi all.i am new on this forum and first of all sry for my english language(is not so good )
i need a bash script to do this:
in usr/xx/rrd ...
- 10-30-2007 #1Just Joined!
- Join Date
- Oct 2007
- Posts
- 10
copy and change file name
hi all.i am new on this forum and first of all sry for my english language(is not so good
)
i need a bash script to do this:
in usr/xx/rrd i have some files x_y_by_ssh.rrd for e.g and i want to make a copy of that file in the same directory but, the new name must be x_y_by_nrpe.rrd and the old file must remain there.i must modifie all the x_y_by_ssh.rrd files to x_y_by_nrpe.rrd
thx alot for your help
- 10-30-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
If you have filenames ending with "_ssh.rrd", you can copy the files as follow:
But try this first, the output must be the copy commands:Code:find /usr/*/rrd/*_ssh.rrd|sed 's/\(.*_\).*\(\..*\)/cp & \1nrpe\2/'|sh
RegardsCode:find /usr/*/rrd/*_ssh.rrd|sed 's/\(.*_\).*\(\..*\)/cp & \1nrpe\2/'
- 10-30-2007 #3Just Joined!
- Join Date
- Oct 2007
- Posts
- 10
thx man



- 10-31-2007 #4Just Joined!
- Join Date
- Oct 2007
- Posts
- 10
sry for another request....my boss want a perl script to do this...can be done?
- 10-31-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Well, since I'm not familiar with perl your boss must have some patience until a perl adept comes along.

Regards
- 10-31-2007 #6Just Joined!
- Join Date
- Oct 2007
- Posts
- 10
thx...i have some day for this...but unfortunataly i don't know programming...i can wait for it
thx again.
- 10-31-2007 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458
Do you want to share your salary with me?

you should start reading a Perl book already.Code:#!/usr/bin/perl use File::Copy; $dir="/usr/xx/rrd"; chdir $dir; while (<*.rrd>) { $filename=$_; $filename =~ s/ssh/nrpe/g; copy($_ , $filename); }
- 10-31-2007 #8Just Joined!
- Join Date
- Oct 2007
- Posts
- 10
ya i know...i must learn some perl...i never made scripts because i nerver need...but now...
..
well...i have some problems with the perl script
- use: command not found
- =/usr/rrd/*.rrd : no such file or directory
- chdir command not found
- syntax error near unexpected token `)'
- `while (<*.rrd>) {'


Reply With Quote