l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jun 24 16:22

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[RESOLVED] Re: [vox-tech] Shell Scripting Question: Getting a directory name from a 'find' result
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RESOLVED] Re: [vox-tech] Shell Scripting Question: Getting a directory name from a 'find' result

Sorry for breaking the thread; I did not have the original message in my
in-box and I wanted to send the final solution I created (is there a way
in SquirrelMail to restore the thread in this situation?).

Once I got out of the mindset of having to use a bash shell script for the
task (thanks to Mike Simons), I came up with this script that does the
trick (specific IP address and directory structure stuff changed to
protect the innocent):

#!/usr/local/bin/perl -w

use strict;
use File::Find;

# $start_dir is the directory passed in the command line.
my $start_dir = shift or die "Usage: $0 <start_dir>\n";

# make sure $start_dir is a directory, and not a file
unless (-d $start_dir) {
  die "Start directory '$start_dir' is not a directory.\n";

# traverse the directory tree
find(\&process, $start_dir);

# change the files in the directory tree
sub process {

        # Only alter files called wwwboard.html
        return unless /\wwwboard.html$/;

  # get the current directory name
  my $dir = $File::Find::dir;

        # create an absolute path to wwwboard.pl
  $dir =~ s/\/part\/of\/directory\/to\/delete\//g;
  my $URL="http://xxx.xxx.xxx.xxx/".$dir."/wwwboard.pl";;

  # Open the file for reading
  unless (open IN, $_) {
    warn "Can't open file $_ for reading: $!\n";

        # Create an output file
  unless (open OUT, "> fixedfile") {
    warn "Can't open file 'new' for writing: $!\n";

        # replace 'action="wwwboard.pl"' with 'action="$URL"'
  while (<IN>) {
    (print OUT $_) or die "Can't write to new file";

        # Close the files
        close (IN);
        close (OUT);

        # make a backup, in case we screwed up
        rename ("wwwboard.html", "wwwboard.html.old");
        rename ("fixedfile", "wwwboard.html");

        # wwwboard.html must have 777 permissions for the wwwboard
software to work
  chmod 0777, 'wwwboard.html';


Thanks again to everyone who responded with suggestions.

Richard S. Crawford

AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford
MSN: underpope@hotmail.com

"It is only with the heart that we see rightly; what is essential is
invisible to the eye." --Antoine de Saint Exupéry

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.