Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: using pipes in a system() call

by mcarlson (Initiate)
on Dec 07, 2005 at 19:07 UTC ( [id://514985]=note: print w/replies, xml ) Need Help??


in reply to using pipes in a system() call

So here is the entire program, this is just a prototype but its just looking through the many home directories we have to find files owned by $UID, and chown's them to the new UID($NEWUID):
#!/usr/local/bin/perl my $UID = 1202; my $NEWUID = 51617; my @home = ( "/home1/", "/home2/", "/home3/", "/home4/", "/home5/", "/home6/", "/home7/", "/home8/", "/home9/", "/home10/", "/home11/", "/home12/", "/home13/", "/home14/" ); my $i = 0; foreach( @home ) { opendir DH, $home[$i] or die "Cannot open $home[$i]: $!"; foreach $dir ( readdir DH ) { next if $dir eq "." or $dir eq ".." or $dir eq ".snapshot" or +$dir eq "TT_DB"; print "find $home[$i]$dir -user $OUN -print | xargs -n 1 chown + -h $NEWUID\n"; system("find $home[$i]$dir -user $OUN -print | xargs -n 1 chow +n -h $NEWUID"); } $i++; }
the output is so:
find /home1/castillo -user 1202 -print | xargs -n 1 chown -h 51617 sh: syntax error at line 1: `|' unexpected
So the command I'm giving it prints out exactly as expected, and running that by hand does work. I guess I don't understand why a | is 'unexpected'. I did try `-print \; |` but that doesn't work either.

Thanks to all who replied.

Mike C

Replies are listed 'Best First'.
Re^2: using pipes in a system() call
by sgifford (Prior) on Dec 07, 2005 at 20:58 UTC
    With a few small changes to avoid trashing my system, and after changing $OUN to $UID, this works for me.

    Maybe it's something weird with your system or your shell?. What kind of system are you on? What is $ENV{SHELL} set to? Does system("ls |cat"); work?

    Or maybe it's an invisible character (like a carriage return) in one of your strings. Try piping the program through cat -e to show any nonprinting characters.

    A third idea is to strace/truss/ktrace your program, to see what it's actually running.

Re^2: using pipes in a system() call
by jfroebe (Parson) on Dec 07, 2005 at 21:03 UTC

    Hi Mike,

    Since you are looking for files in a specified set of directories, you may want to take a look at File::Find -- no sense in reinventing the wheel ;-)

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://514985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found