Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

chmod permission issues

by tux242 (Acolyte)
on Nov 20, 2003 at 20:36 UTC ( [id://308691]=perlquestion: print w/replies, xml ) Need Help??

tux242 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to resolve a permissions issue with either a touch from the shell side in an if then equality clause like if file is not present then create file in the script below so i do not have to chmod every 5 seconds through the iteration, any suggestions for this fix using Perl

#! /usr/bin/perl use strict; use warnings; my @SERVERS = ('server','server2','server3'); my $path = "/home/backup/nightly"; foreach my $this_server ( @SERVERS ) { #`if $this_server eq 0 then touch $this_server`; `chmod 775 *`; `cp $path/$this_server/etc_passwd ./passwds.$this_server`; `chmod 775 *`; }

Thanks in advance.

Replies are listed 'Best First'.
Re: chmod permission issues
by Roy Johnson (Monsignor) on Nov 20, 2003 at 20:44 UTC
    chmod is a builtin function in Perl. However, you should be able to preserve permissions with the -p option to cp.
Re: chmod permission issues
by asarih (Hermit) on Nov 20, 2003 at 23:24 UTC
    I think you want to look at umask.

    But a bigger question is: Why do you want to use perl for this? When you have so many backticks, you should question if perl is the right tool at all.

    It is much simpler in shell. For example, in ksh:

    umask 002 set -A SERVERS server server2 server3 path="/home/backup/nightly" while (( $i < ${#SERVERS[*]} )); do cp ${path}/${i}/etc_passwd passwds.${i} (( i = i + 1 )) done

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found