Gossamer Forum
Home : General : Internet Technologies :

php script to execute other scripts

Quote Reply
php script to execute other scripts
Hey,

I'm hoping someone can provide me with an easy solution here. My crontab file is getting awfully long and is a rather pain to edit. I'd like to have it run just a single php script, but within that php script, I'd like it to execute a variety of other scripts on a variety of other servers. They can all run back to back, so I don't need to schedule custom times for each script to run.

It would just be easier for me to maintain a single php script that can execute other scripts, rather than maintain multiple crontab files on multiple servers.

Any help would be greatly appreciated!

Another note, all of these "sub" scripts I'd like to run, I can access these all in a browser such as example.com/somesript.php and the script will perform the function I need.

Robert
http://www.pcprofiles.com
PC Profiles and hardware reviews

Last edited by:

Robert_B: Jul 31, 2005, 9:44 PM
Quote Reply
Re: [Robert_B] php script to execute other scripts In reply to
..or a Perl script? :P

Code:
#!/usr/bin/perl

my @commands = split /\n/, qq{perl /path/to/script.cgi
another command
date
cp * ../baks/
..etc
};

foreach (@commands) {
chomp;
s/[\s\n\t]+$//sig;
s/^[\s\n\t]+$//sig;
next if length($_) < 3;
print "Running: $_ \n";
system($_);
}

Call with:

perl /full/path/to/script.cgi

Hope that helps Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] php script to execute other scripts In reply to
Hi Andy,

Yea, Perl would definitely work...

But I can't get it to run in the fashion I need; I probably didn't explain myself well enough (I tend to do thatWink)

I have scripts at the following URLs on completely different servers:
http://www.somesite.com/somescript1.php
http://www.anothersite.com/anotherscript2.cgi?update=1
etc.

Basically if I'd manually type those urls in my browser, I could run them, but naturally I don't want to do that for all of them.

Any insights?

Thanks again, your help is appreciated very much!

Robert
http://www.pcprofiles.com
PC Profiles and hardware reviews
Quote Reply
Re: [Robert_B] php script to execute other scripts In reply to
Ah, in that case.. try using wget;

wget -Ofilename.txt ' http://www.anothersite.com/anotherscript2.cgi?update=1'

..and if you need to specify a user/pass for that folder;

wget -Ofilename.txt ' http://user:pass@www.anothersite.com/anotherscript2.cgi?update=1'

Hope that helps =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] php script to execute other scripts In reply to
Ok, so would this be essentially what I need (I'd test this out b4 asking, but I'm stuck at work, not to mention I really don't know perl as good as I should Unsure)

From what I read about wget, I take it that it just writes the contents of that script to filename.txt, so it could rewrite that file everytime a different script is called, hence I used filename.txt for all of them. Or do I need a unique one for each script I want to run, such as filename2.txt, filename3.txt, etc?

Code:


#!/usr/bin/perl

wget -Ofilename.txt ' http://www.somesite.com/somescript1.php'
wget -Ofilename.txt ' http://www.anothersite.com/...cript2.cgi?update=1'

Robert
http://www.pcprofiles.com
PC Profiles and hardware reviews

Last edited by:

Robert_B: Aug 1, 2005, 7:45 AM
Quote Reply
Re: [Robert_B] php script to execute other scripts In reply to
Hi,

Yeah, almost Smile

Try this;

Code:
#!/usr/bin/perl

`1wget -Ofilename.txt ' http://www.somesite.com/somescript1.php' `;
`wget -Ofilename.txt ' http://www.anothersite.com/...cript2.cgi?update=1'`;

print "DONE!!!";

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] php script to execute other scripts In reply to
Worked like a charm, thanks!

Robert
http://www.pcprofiles.com
PC Profiles and hardware reviews
Quote Reply
Re: [Robert_B] php script to execute other scripts In reply to
Cool