Use Webpage to Start Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use Webpage to Start Script
# 1  
Old 04-03-2012
Use Webpage to Start Script

I apologize if this is in the incorrect section, I'm not quite sure which section it should go in.

Anyways...
I've got a script that I'd like to be able to start with a webpage, something that just has a button that says "Start this Bot", which will start the bot and put it in the background. How would I do this/can someone provide me with a simple HTML file that would do this using PHP?

Assume the path is: /home/bots/rcbot.pl
# 2  
Old 04-03-2012
The button and the code will actually be different pages, because when you click the button, that loads a separate, independent webpage, see? Each time you interact with CGI, it's a fresh page. The only things which come with it are things you put in every time.

Have your form load a PHP page with this in it:
Code:
<?php system("nohup /home/bots/rcbot.pl & disown"); ?>

# 3  
Old 04-05-2012
Quote:
Originally Posted by Corona688
The button and the code will actually be different pages, because when you click the button, that loads a separate, independent webpage, see? Each time you interact with CGI, it's a fresh page. The only things which come with it are things you put in every time.

Have your form load a PHP page with this in it:
Code:
<?php system("nohup /home/bots/rcbot.pl & disown"); ?>

I'm sorry, I guess I need to add two more things I forgot...

I need user "bots" to run this (password auth is off, have to use key for authentication), and if possible, it should check to see if the file/bot is already running and if it is, either return an error or kill the process. Is this possible to add to that code that was provided?

---------- Post updated 04-05-12 at 03:24 PM ---------- Previous update was 04-04-12 at 04:31 PM ----------

Is anyone able to help now that I've given a few more specifics? I'm not quite sure how to do this, thanks!
# 4  
Old 04-05-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 5  
Old 04-05-2012
You'll have to configure sudo to allow you to run the script as another user, since your webserver probably runs as the apache user and group.

Add lines like this using visudo:

Code:
apache ALL = NOPASSWD:(bots) /home/bots/rcbot.pl
apache ALL = NOPASSWD:(bots) kill

Then a php script like:

Code:
<html><body>
<?php   $scr=<<<EOF
        # Let you see errors
        exec 2 > &1
        # Kill old script
        read PID < /tmp/botpid && sudo -u bots kill "\$PID"
        # Run new script
        nohup sudo -u bots /home/bots/rcbot.pl > /dev/null &
        # Save new PID
        echo "$!" > /tmp/botpid
EOF;

        echo "<pre>", $scr, "</pre>";
        system($scr);
        ?>
</body></html>

Since this doesn't do an actual shell login to bots, things like PATH may not be fully set.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing Shell Script from PHP Webpage

Hello , I am trying to execute a small shell script from a PHP Webpage. Below is the shell script : 1.sh $ cat /home/oracle/rahul/1.sh #!/bin/ksh echo "`date` : Report generation in progress" > /home/oracle/rahul/report.txt echo "Run successfully script"; Below is the PHP... (1 Reply)
Discussion started by: rahul2662
1 Replies

2. Shell Programming and Scripting

Launch shell script with parameters from a webpage button

I want to create a simple html page that should contain 2 fields in which the user can write the input. Then I want to have a button that should launch a shell script with the parameters inserted by user in the fields from the webpage. This is the code behind my webpage: <html> <form... (2 Replies)
Discussion started by: black_fender
2 Replies

3. Shell Programming and Scripting

Perl Script - Sort Columns on webpage

foreach my $ds (sort { $a->{books} cmp $b->{books} || (($a->{books} eq "A") ? ($a->{hammers} cmp $b->{hammers}) : (($a->{shoes} <=> $b->{shoes}) || ($a->{hammers}... (1 Reply)
Discussion started by: scj2012
1 Replies

4. UNIX for Dummies Questions & Answers

Script to if webpage is: forbidden, Error...

I have a file with about 29,000 website names. I would like to find a script that would test if each website name is current/active or not. If not it should check if the page is: Forbidden, 404 Error... (1 Reply)
Discussion started by: dcovnton
1 Replies

5. Shell Programming and Scripting

open a webpage through perl script

Hi All Can anyone please help me how to open a webpage suppose(Google) with the help of perl script and refresh it after every 5 minutes. (0 Replies)
Discussion started by: parthmittal2007
0 Replies

6. Shell Programming and Scripting

Read webpage from shell script

Hey experts, I am trying to read a webpage and want to search for a text patter (case insensitive). Please help me acquire this. If the text is found i will receive a mail which can be hardcoded in the script. I am not a big fan of using PERL script. Please help. Machine: AIX... (15 Replies)
Discussion started by: bankimmehta
15 Replies

7. Shell Programming and Scripting

Run a script from a webpage

Hello, I was trying to run a shell script when I click on webpage link. My webpage is hosted on Sun One web server. This is something I was looking, Chris Johnson's Test Bed I already have my shell script and it works fine when I run it from the command line. Can somebody tell me what are... (3 Replies)
Discussion started by: grajp002
3 Replies

8. Web Development

php script + not displaying webpage

Hi guys Im in the process of designing a website for my company which does the following 1) Daily execution a perl script. The perl script's output is diverted to a .html file. 2) The .html file generated from 1) sets up a centralised webpage showing options as radio buttons (the radio... (1 Reply)
Discussion started by: JamesGoh
1 Replies

9. Shell Programming and Scripting

Calling an Expect script from a Webpage using PHP

I have a webpage that is in HTML and PHP. In PHP I have tried using exec, system, shell_exec and passthru functions to call an Expect Script file (temp.exp). This Expect file spawns a telnet session that uses "expect/send" commands to retrieve information from an environmental unit (not a normal... (0 Replies)
Discussion started by: CCUSmith
0 Replies

10. Shell Programming and Scripting

Help with perl script to search webpage

i have to point out that i'm a avid shell script lover and i have next to zero interest in perl which is why i dont know the first thing about it. however, just need to do this one thing on it.. i need to do something in perl but dont know how. I have a list of email addresses in the following... (5 Replies)
Discussion started by: Terrible
5 Replies
Login or Register to Ask a Question