bash - Grant write permission to a Perl script when it is called from a shell script regardless of user -


i have function in bash shell script called upon start-up of the script. function performs sort on data file, calls perl script checks see if backup of script , data files needs performed, if perl script makes backups , compresses backups in backup directory. bash , perl scripts work fine when run bash script, other users getting errors returned perl script says not have permission write files. how elevate permissions of perl script user can write directory? have directory files written read write permissions users, users still error upon opening bash script.

tar: /absolute/path/to/file/location/filename.tar.gz: cannot >open: permission >denied tar: error not recoverable: exiting now

this function in bash script calling perl script

sourcefile(){ # sorts script source file in alphabetical order each time script runs. sort /absolute/path/to/data-file.txt -o /absolute/path/to/data-file.txt # # calls perl script run backups of script , data files. /absolute/path/to/location/./scrpt_maint.prl #        }   

this perl script creates backups

#!/usr/bin/perl  ## use strict;  use warnings; ##  use file::stat; use time::localtime; use time::local; use file::copy; ## $source = "/path/path/path/backup/filename.sh.bak"; $today = time; $modtime = (stat($source)->mtime); $interval = 86400; #- =24 hours in seconds $delta = ($today - $modtime); # # $interval = 30; #- =30 second intervals testing #  $src_scripts = "/path/path/path/"; $target_scpts = "/path/path/path/backup/"; # ###############################  if ( $delta >= $interval ) {                 &backup;                 system "tar -czf     /path/path/path/backup/compressed/filename.tar.gz -c /     /path/path/path/backup/compressed";   } # sub backup { # opendir(my $scripts, $src_scripts ) || die "can't opendir $src_scripts: $!"    ;  @scripts = readdir($scripts);  foreach $t (@scripts) {          if( -f "$src_scripts/$t" ) {                 copy "$src_scripts/$t", "$target_scpts/$t.bak" || warn "copy     of $t $target_scpts failed: $!";                 } }  } # exit; 

i no means shell or perl expert, if these sloppy or not best practice, why. not admin , not have root access linux server. writing in red hat enterprise linux release 4

thanks

ok, based on comments problem was:

drwxrw-rw- 2 username ncs 4096 may 14 12:46 compressed  

the permissions on filename.tar.gz were, -rw-r--r-- chmod'ed them -rw-rw-rw

solution was:

chmod a+x compressed chmod a+rw filename.tar.gz 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -