Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

SelfChanging script!

by Nik
on Aug 04, 2003 at 12:07 UTC ( #280644=perlquestion: print w/ replies, xml ) Need Help??
Nik has asked for the wisdom of the Perl Monks concerning the following question:

i want to make a perl script that it will change itself automatically every hour. for example i want its size to be doubled every hour. can this be done? is this possible??

after some searching i came up with this one!

#!/usr/bin/perl $id = fork; print $id; if ($id) { exit; } while (1) { open( 0, ">>$0" ); print {0} " " x -s $0; close(0); sleep(10); }
my question now is that i want myscript to run by itself every hour. can this be done? is this possible? i dont want any other program to trigger it i want it to trigger itself to run. is this possible? and if so, how??

I am talking about having my program to sleep, and waiting for a trigger to execute! trigger would be lets say some specific date... can this be done?

update (broquaint): added formatting

Comment on SelfChanging script!
Download Code
Re: SelfChanging script!
by Juerd (Abbot) on Aug 04, 2003 at 12:09 UTC

    (...) i want its size to be doubled every hour (...) I am talking about having my program to sleep, and waiting for a trigger to execute! trigger would be lets say some specific date...

    I don't think many monks will help people write viruses or virus-like programs.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      Well caught possible intention.
Re: SelfChanging script!
by Abigail-II (Bishop) on Aug 04, 2003 at 12:24 UTC
    What do you mean by "trigger itself to run"? For a program to trigger anything, it must run. It can't do anything, unless it runs. And since you specifically disallow another program to do this triggering, it isn't at all clear to me what you mean.

    For a program that sleeps, there are two, and only two, ways of how it can be awakened: it reaches the end of the interval it went asleep for, or it caught a signal (and with some implementation of sleep, this is the same thing).

    Perhaps you could explain what your ultimate goal is?

    Abigail

Re: SelfChanging script!
by Beatnik (Parson) on Aug 04, 2003 at 13:13 UTC
    Actually.. after a rather long IRC conversation with me, I came up with THAT one :)

    Greetz
    Beatnik
    ... I'm belgian but I don't play one on TV.
Re: SelfChanging script!
by smalhotra (Scribe) on Aug 04, 2003 at 14:12 UTC
    Sounds a little bit like homework. (maybe a theoretical computer science class?).

    Anyways, I'm sure the Monks are more than willing to help you out if you provided some more information/feedback.

    $will->code for @food or $$;

Re: SelfChanging script!
by bm (Hermit) on Aug 04, 2003 at 15:49 UTC
    my question now is that i want myscript to run by itself every hour. can this be done? is this possible?

    Yes, this is possible. But it has nothing to do with Perl (at first glance anyway).

    On *nix systems, this is a job for cron, look at  man cron

    On Win32, Start -> Accessories -> System Tools -> Scheduled Tasks

Re: SelfChanging script!
by sgifford (Prior) on Aug 04, 2003 at 21:03 UTC
    If you want it to run every hour, something simple like:
    sleep(60*60); exec($0,@ARGV);
    should work. The script needs to exec itself (or use something like eval or do) because otherwise Perl won't recompile it, and so won't see the changes.
Re: SelfChanging script!
by Anonymous Monk on Aug 05, 2003 at 03:13 UTC
    i dont want any other program to trigger it i want it to trigger itself to run. is this possible? and if so, how??

    Have it run as a cron job, or have a separate program run as a daemon and activate it when required.

    I don't usually ask these things (mostly because I don't care) but I'm curious, could you explain what the purpose of the program is? I can't see this being for malicious purposes, because even the most primitive of script kiddies would realize the flaws in this approach. If it's just for experimentation, you should choose a less destructive task.

    Look at this post's reputation and current replies, many have already made their ignorant judgements. If you provide some more information I can probably help you out, or at least suggest a more educational alternative.

    Cheers.

    P.S. A note to all those who worry about these things - take another look. If some primitive self-replicating Perl source can cause any damage whatsoever, much, much worse will happen. Focusing on false threats at the cost of research is what's causing so many of our current problems. So I suggest you all get a clue, or at least stop spreading blind FUD. Thanks.

      If it's just for experimentation, you should choose a less destructive task.

      Or, more appropriately, a task that provides more educational benefits.

      P.S. A note to all those who worry about these things - take another look. If some primitive self-replicating Perl source can cause any damage whatsoever, much, much worse will happen. Focusing on false threats at the cost of research is what's causing so many of our current problems. So I suggest you all get a clue, or at least stop spreading blind FUD. Thanks.
      I'd like to ask first ... how is this indicitave of "much worse will happen"? There are plenty of cases of attacks on server where the basic methodolgy is to simply fill all available disk space on a partition. If this 'harmless' script gets executed with enough access, it could bring a server to its knees by filling it up.

      If it was simply research, why the need to double itself in size? If its simply research, the problem is creating a persistant program that runs itself over and over. The way the question is posted smacks of either poor intents, or, even worse, a homework assignment.

        The way the question is posted smacks of either poor intents, or, even worse, a homework assignment.

        And you care if it's a homework assignment, why? Because someone is willingly allowing you to sabotage their education? Who cares, less competition for your job (which is a good thing for you if you think that Perl program is a major security threat). Or maybe because someone else will read the thread and learn in the process? Or that, when you're replying to the post, someone corrects an error of yours and you learn something new because of it? Gee, those homework questions sure do damage...

        If this 'harmless' script gets executed with enough access, it could bring a server to its knees by filling it up.

        If they have the privileges to execute this script and have malicious intents, they can do far, far worse than fill up some disk space. Worry about the privilege escalation first, then worry about more damaging options. After you've solved those, you can worry about filling up disk space.

        If it was simply research, why the need to double itself in size? If its simply research, the problem is creating a persistant program that runs itself over and over.

        Because that's the first thing that popped into his or her head? Because he wanted to learn more about the language and operating system he or she was using and decided this might be a good way? Maybe the goal was to test a new security tool.

        I'd like to ask first ... how is this indicitave of "much worse will happen"?

        Because far more damaging tools already exist. Because thousands and thousands of people know how to cause massive damage on a widespread scale. Unless people start getting a clue about these threats, we're going to problems that make every incident to date look like harmless pranks. By claiming that something like this poses a security threat, you trivialize the real threats and make people feel safe.

        Anyways, these problems aren't going to be solved on "Perl Monks" so I'll be on my merry way now. Later.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-12-21 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls