How-To question for the NC*SA brain trust...

Kurt Werth kurt.d.werth at baesystems.com
Tue Mar 16 11:06:54 EST 2004


Here's some perl that'll help, assuming that your data is only broken up by
a single set of spaces. You can put the chmod right in the script or output
a new file without the spaces. I can give you those pieces too if you're not
familiar with perl.

#!/usr/local/bin/perl
open(NC,"/tmp/nc.dat");  #nc.dat is your input file
while (<NC>) {
 chomp;
 my @data=split(/ +/);
 print "$data[0]$data[1]\n";
}

$ perl nc
/usr/local/foobar/file1
/usr/local/foobar/file2
/usr/local/foobar/



-----Original Message-----
From: ncsa-discussion-bounces at ncsysadmin.org
[mailto:ncsa-discussion-bounces at ncsysadmin.org]On Behalf Of Gantt
Edmiston
Sent: Tuesday, March 16, 2004 10:54 AM
To: ncsa-discussion at ncsysadmin.org
Subject: How-To question for the NC*SA brain trust...



Here's a question for you all, something that should be much simpler than
it has become.... I'll lay it out simply, the real situation is more
detailed,
but the example below will represent the problem that I have and hopefully
allow someone to provide the solution we need.

Here is a brief extract from a 1200 line data file, named LIST,
of fully qualified pathnames to files:

/usr/local/foo bar/file1
/usr/local/foo bar/file2
/usr/local/foo bar/

NOTE carefully, the whitespace in the directory name "foo bar".
The actual filenames vary, the only consistent thing is that there is
one space in the fully qualified pathnames.

The task is to execute a "chmod o-w" on the 2 files and 1 directory
shown above.
Keep in mind, that real need is to do this on over 1200 of similar FQ
pathnames.
So the real task is to do this permissions change over a large number of
files,
thus the absolute need to do this programmatically.

Normally, in bash, I would do:
    for x in $(cat LIST)
      do
      chmod o-w $x
      done

But the shell has issues with the white space and the whole thing fails.
It sees the section on the left as the first record and the second right
of the whitespace as the second record and so on.

I've tried quoting (single and double), I've tried quoting the paths in
the datafile and I've tried adding back-slashes, all without positive
effect.

If someone can post a solution, I'd be most appreciative.

TIA

Gantt
gantte at bellsouth.net




_______________________________________________
ncsa-discussion mailing list
ncsa-discussion at ncsysadmin.org
http://www.ncsysadmin.org/mailman/listinfo/ncsa-discussion



More information about the ncsa-discussion mailing list