Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    10

    Smile 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

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    If you have filenames ending with "_ssh.rrd", you can copy the files as follow:

    Code:
    find /usr/*/rrd/*_ssh.rrd|sed 's/\(.*_\).*\(\..*\)/cp & \1nrpe\2/'|sh
    But try this first, the output must be the copy commands:

    Code:
    find /usr/*/rrd/*_ssh.rrd|sed 's/\(.*_\).*\(\..*\)/cp & \1nrpe\2/'
    Regards

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    10
    thx man

  4. #4
    Just Joined!
    Join Date
    Oct 2007
    Posts
    10
    sry for another request....my boss want a perl script to do this...can be done?

  5. #5
    Linux 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

  6. #6
    Just 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.

  7. #7
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Do you want to share your salary with me?
    Code:
    #!/usr/bin/perl 
    use File::Copy;
    $dir="/usr/xx/rrd";
    chdir $dir;
    while (<*.rrd>) {
     $filename=$_;
     $filename =~ s/ssh/nrpe/g;
     copy($_ , $filename);
    }
    you should start reading a Perl book already.

  8. #8
    Just 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>) {'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...