Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

mkdir permission

by seafree (Novice)
on Jan 08, 2019 at 16:18 UTC ( #1228217=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I'm using Centos 7 and I had been to execute mkdir in perl from web, but it's not executed, the /etc/profile has:
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; +then umask 002 else umask 022 fi

1er. condition:

apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

2do. Condición:

root=root

The condition is false, so umask=022

File permissions for upload files: first I created a directory using mkdir from perl but it's not create:

my @archivos = $cgi->param("archivos"); my $inst = $cgi->param("inst"); my $fecha = $cgi->param("date1"); my $anio=substr($fecha,2,2); my $mes=substr($fecha,5,2); my $dia=substr($fecha,8,2); my @nombre_archivos = ("NI","RP","RDZ","CRF"); my $upload_dir = "/var/www/html/public_html/rev/$inst/$anio-$mes-$dia" +; mkdir $upload_dir, 0775;

BUT THE DIRECTORY WASN'T BEEN CREATE.

Please will you help me? The permissons that I had been set are:

#/var/www/html drwxr-xr-x. 5 apache apache 4096 Dec 20 15:00 public_html

The error web messages is:

Software error: No such file or directory at /var/www/cgi-bin/programs/upload_modif_ok +.cgi line 49.

Line 49 is:

open ( UPLOADFILE, ">$upload_dir/$anio-$mes-$dia-$nombre_archivos[$ind +]" ) or die "$!";
For help, please send mail to the webmaster (root@localhost), giving t +his error message and the time and date of the error.

The /varlog/http/error has:

[Tue Jan 08 09:43:34.876310 2019] [cgi:error] [pid 31695] [client...] +AH01215: [Tue Jan 8 09:43:34 2019] upload_modif_ok.cgi: No such file + or directory at /var/www/cgi-bin/programs/upload_modif_ok.cgi line 4 +9., referer: http://...

Thanks a lot.

Regards. Seafree

Replies are listed 'Best First'.
Re: mkdir permission
by poj (Abbot) on Jan 08, 2019 at 17:20 UTC

    Perhaps you need to create the intermediate sub directories first.

    #!/usr/binperl use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; # add this only during debugging my $cgi = CGI->new(); my @nombre_archivos = ("NI","RP","RDZ","CRF"); my $archivos = $cgi->param("archivos"); # warning list context ? my $inst = $cgi->param("inst"); my $fecha = $cgi->param("date1"); my ($anio,$mes,$dia)= unpack 'x2 a2 x a2 x a2',$fecha; my $ymd = join '-',$anio,$mes,$dia; my $upload_dir = "/var/www/html/public_html/"; for my $subdir ('rev',$inst,$ymd){ $upload_dir .= $subdir.'/'; unless (-d $upload_dir){ mkdir $upload_dir, 0775 or die "Could not mkdir $upload_dir : $!"; } } my $ind = 1; my $filename = "$upload_dir/$ymd-$nombre_archivos[$ind]"; open UPLOADFILE, '>', $filename or die "Could not open $filename : $!"; # add filename into error + message print UPLOADFILE "Test"; close UPLOADFILE;

    Update : Or alternatively use make_path using File::Path

    poj
Re: mkdir permission
by haukex (Archbishop) on Jan 08, 2019 at 16:26 UTC

    Note that questions about Perl should be posted to Seekers of Perl Wisdom - I tried to move your post but it seems something went wrong (Update: nevermind, looks like it did work). Also, as I already messaged you, please use <code> tags to format code, as well as sample input and output.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-10-02 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (7 votes). Check out past polls.

    Notices?