deleting files with perl

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Ok I've consulted my PERL books, I've searched this forum, but for somereason I can't seem to delete a file from within my perlscript. I am using unlink like this..

CODE------------
unlink ("../sites/$num.shtml");
CODE------------

Is there something wrong with this code? Or does the file have to have certain permissions to be deleted by the script?
Thanx
VulKen

Pimpin like a pimp with an electrofied pimpin machine!

They have: 193 posts

Joined: Feb 2000

I don't use the parenthesis, but I doubt that matters. Also, I think it is only your example, but I don't believe PERL will handle relative paths like that?

If you think it might be the permissions, try chmoding the file to 755 then deleting it:

code:

chmod(0755, "../sites/$num.shtml");

unlink ("../sites/$num.shtml");
[/code]

Hope that helped?

Richard

------------------
        [email protected]         

 http://gimmeabuck.com  - I'll give my buck...you give yours. lol 

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 568 posts

Joined: Nov 1999

CGI scripts are executed as user "nobody". Unless your using SUSEXEC (is that right?). So if your server admin has set it so that you can't delete files as user "nobody" than it's impossible.

Unless he'll activate that program, then you can execute commands as your own user name.

But that's all useless if your on windows OS.

They have: 193 posts

Joined: Feb 2000

Orpheus,

Your probably right. My server automatically runs my scripts as user "ME." That way I don't have to worry about anything.

Create a file called whoami.cgi Put the following code in it:

code:

#!/usr/bin/perl

BEGIN {
 use CGI::Carp qw(fatalsToBrowser);
}

use CGI qw(param header);
print header;

print `whoami`;
[/code]

If the script prints your username, then the scripts are ran with your rights, if the script does not return your username, contact your host and ask them to make your scripts run with your permissions, or switch hosts.

Hope that helped.

Richard

------------------
        [email protected]         

 http://gimmeabuck.com  - I'll give my buck...you give yours. lol 

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.