Imean i have a script that saves all settings to a data file.
then other script runs fine on the data input from the data file.
now i want the first script to be delted after it saved the fom input .
this to avoid peopel forget to delete the script and then others can change settings.
what kind of coding should ithink of
so the script afterform has been submited that the script removes it self from server?
[perldoc.com...]
Ill' say just enough to make it possible for you to construct it yourself, possibly using perl documentation but i'll sure as **** will not wipeout your web site for you. This can happen if you abuse any of this, so be very careful.
This tiny perl script will delete the file "examplescript.cgi":
#!/usr/bin/perlunlink("examplescript.cgi");
Use with caution, please. The file will get deleted. Here's another version, that deletes the file calling it:
#!/usr/bin/perl$deleteThisString = %ENV{HTTP_REFERRER};
unlink($deleteThisString);
Again Use with extreme caution, please
Then, how to call another perl script from a perl script? Try this line:
system ("perl path/to/otherscript.pl");
Now, i simply do not dare to tell you more, apart from this: These examples are not guaranteed to work on your server, they're only examples to get you started. Remember to set proper file permissions and paths.
/claus
if deleting files is dangeruos i could try open the file
and rewrite the file so all code inside gets cleared and only a htmltag gets printed
this way script has become useless
i could try this
if i use the other way like:
#!/usr/bin/perl
unlink("examplescript.cgi");
can i put any other code bellow this coding?
i mean i can add it to a ecsisiting script?
I must stress, though, that using my examples as they are above could potentially be dangerous - they do not have any kind of security checks built in, they just delete files, no matter who asks, as long as it's allowed by the file system. In other words, they will do the job, even if you make a mistake, or someone deliberately abuses them.
The overwrite-method is actually the same thing. It's not really dangerous unless it can be used or abused to do something else than what you want.
On this question:
can i put any other code bellow this coding?
i mean i can add it to a ecsisiting script?
- the answer is yes and no:
1) Yes, you can put code anywhere below this line:
#/usr/bin/perl
Mind you, the first line under this line should be blank.
2) No, you can not include the whole thing in another script, as this script will probably already have one such line (#/usr...). You can include this line, though:
unlink("examplescript.cgi");
But as you already know how to write to a file, i suggest you do something else than deleting the script.
The problem is that you only want to run the original script once. This can be solved without deleting it.
Just add a line to the start of your "run-once" script, that checks if a file called "onetime" exists, and if it does, stop the script and do nothing ("die").
Then (here's the clever part) add a line to the end of the script, telling it that after it has done what it is supposed to, it scould create a file named "onetime"
In that way, the script will only run once, and you don't have to delete or overwrite files - plus, it's safer :)
/claus
unlink $0 or die "Unable to unlink $0. $!";
before you try it, I suggest that you make a copy of your script so that when it deletes itself, you're not sorry.
As someone has already told you, "unlink" deletes files in perl. (well, it really unlinks them. Your OS deals with deleting.) In perl, the $0 refers to the filename of the currently running script. See the "perlvar" man page for more information on that.
As has already been suggested, you can probably do better by not deleting the script. You can make it check to see if it has been run already, or change its own permissions, or something like that and probably have better results.
Hope it helps.
-Andy
i willadd it to near the end of script one.
as it would save me time .
im nopro in programming and making it to check if
has run takes me more time igo tryboth..
unlink $0 or die "Unable to unlink $0. $!";
and the checkif has run before
thx