Results 1 to 9 of 9

Thread: run a basic command from webpage

  1. #1
    Join Date
    Aug 2005
    Location
    Sweden
    Beans
    395
    Distro
    Ubuntu

    run a basic command from webpage

    Hi I have a little basic command that I like to run on a webpage

    With this command I can capture a image and create a image of it.


    Code:
    fswebcam -d /dev/video0 -r 1280x960 /var/www/cam/bild.jpeg
    I did try to make CGI file and give it +x


    Code:
    #!/bin/bash
    fswebcam -d /dev/video0 -r 1280x960 /var/www/cam/bild.jpeg
    But what I can see in the apache2 log I get a permission denied.

    Is it any way that I can run this command from a webpage?

    I was thinking that I just need to push a button, and it create a image and I and watch it from another place?
    Cazz

  2. #2
    Join Date
    Oct 2010
    Location
    Buffalo, New York
    Beans
    523
    Distro
    Ubuntu

    Re: run a basic command from webpage

    Quote Originally Posted by cazz View Post
    Hi I have a little basic command that I like to run on a webpage

    With this command I can capture a image and create a image of it.


    Code:
    fswebcam -d /dev/video0 -r 1280x960 /var/www/cam/bild.jpeg
    I did try to make CGI file and give it +x


    Code:
    #!/bin/bash
    fswebcam -d /dev/video0 -r 1280x960 /var/www/cam/bild.jpeg
    But what I can see in the apache2 log I get a permission denied.

    Is it any way that I can run this command from a webpage?

    I was thinking that I just need to push a button, and it create a image and I and watch it from another place?
    There are 3 possible problems you may have had.

    Problem #1 (the file extension):
    You'll have to specify the mime extension type in the Apache configure files. By default cgi is already specified. What is the full name of the bash file you tried to run?

    Problem #2 (Output type):
    The first line of the script should specify the output type (ie: text/html)). There needs to be a blank line after the type definition to start your output.

    Problem #3 (Directory permission):
    By default Apache is set to only allow cgi files to be executed in the cgi-bin directory. If your exec script is outside the cgi-bin directory you'll have to declare the ExecCGI directive.

    Try this test bash file both in your cgi-bin and specific directory area.

    test.cgi:
    Code:
    #!/bin/bash
    
    echo -ne "content-type: text/html\n\n"
    
    echo -ne "<title>Bash File Example</title>"
    echo -ne "Hello from bash\n"
    echo "<hr>"
    
    echo "This is today's date: "
    
    date
    -- L. James

    --
    L. D. James
    ljames@apollo3.com
    www.apollo3.com/~ljames

  3. #3
    Join Date
    Aug 2005
    Location
    Sweden
    Beans
    395
    Distro
    Ubuntu

    Re: run a basic command from webpage

    Thanks for the fast replay

    Answer 1
    The name of the file is cam.cgi

    Answer 2
    I did try that but same problem
    Code:
    #!/bin/bash
    
    fswebcam -d /dev/video0 -r 1280x960 /var/www/cam/bild.jpeg
    Answer 3
    I did run that script in my cgi-bin folder and it works.
    I'm not going to have any .cgi file in my www directory.
    I have ExecCGI in my default file.
    Code:
            ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
            <Directory "/usr/lib/cgi-bin">
                    AllowOverride None
                    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                    Order allow,deny
                    Allow from all
            </Directory>
    When I run
    Code:
    tail -f  /var/log/apache2/error.log
    and trying to run my cgi file I got

    Code:
    Trying source module v4l2...
    \x1b[0m\x1b[31mError opening device: /dev/video0
    \x1b[0m\x1b[31mopen: Permission denied
    \x1b[0m\x1b[0mTrying source module v4l1...
    \x1b[0m\x1b[31mError opening device: /dev/video0
    \x1b[0m\x1b[31mopen: Permission denied
    \x1b[0m\x1b[31mUnable to find a source module that can read /dev/video0.
    \x1b[0m
    Premature end of script headers: cam.cgi
    Last edited by cazz; November 20th, 2012 at 06:40 PM.
    Cazz

  4. #4
    Join Date
    Oct 2010
    Location
    Buffalo, New York
    Beans
    523
    Distro
    Ubuntu

    Re: run a basic command from webpage

    Quote Originally Posted by cazz View Post
    Thanks for the fast replay

    Answer 1
    The name of the file is cam.cgi

    Answer 2
    I did try that but same problem
    Code:
    #!/bin/bash
    
    fswebcam -d /dev/video0 -r 1280x960 /var/www/cam/bild.jpeg
    Answer 3
    I did run that script in my cgi-bin folder and it works.
    I'm not going to have any .cgi file in my www directory.
    If you only want your scripts to be executed from teh cgi-bin file then you're in business.

    Glad for your success.

    As a contribution back to the forum, please take the time to mark the thread solved so that others can benefit from the solution. You can find this option under the Tread Tools link.

    -- L. James

    --
    L. D. James
    ljames@apollo3.com
    www.apollo3.com/~ljames

  5. #5
    Join Date
    Aug 2005
    Location
    Sweden
    Beans
    395
    Distro
    Ubuntu

    Re: run a basic command from webpage

    Yes I just like to run the commander from my cgi-bin folder
    I get error when I trying with http://<ipnumber>/cgi-bin/cam.cgi
    Cazz

  6. #6
    Join Date
    Oct 2010
    Location
    Buffalo, New York
    Beans
    523
    Distro
    Ubuntu

    Re: run a basic command from webpage

    Quote Originally Posted by cazz View Post
    Yes I just like to run the commander from my cgi-bin folder
    I get error when I trying with http://<ipnumber>/cgi-bin/cam.cgi
    What error are you getting? The solution would depend on the error.

    -- L. James

    --
    L. D. James
    ljames@apollo3.com
    www.apollo3.com/~ljames

  7. #7
    Join Date
    Aug 2005
    Location
    Sweden
    Beans
    395
    Distro
    Ubuntu

    Re: run a basic command from webpage

    I get a 500 Internal Server Error

    and when I read the apache2 error log I have

    Code:
    Trying source module v4l2...
    \x1b[0m\x1b[31mError opening device: /dev/video0
    \x1b[0m\x1b[31mopen: Permission denied
    \x1b[0m\x1b[0mTrying source module v4l1...
    \x1b[0m\x1b[31mError opening device: /dev/video0
    \x1b[0m\x1b[31mopen: Permission denied
    \x1b[0m\x1b[31mUnable to find a source module that can read /dev/video0.
    \x1b[0m
    Premature end of script headers: cam.cgi
    Cazz

  8. #8
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: run a basic command from webpage

    @OP: Here is my guess what could be wrong.

    CGI scripts are run as a certain user by Apache (www-data, I think, for Ubuntu). This user would typically not have access to /dev/... by default. So either change this (give that user access to \dev\video*), or use something like suexec: http://httpd.apache.org/docs/2.0/suexec.html

  9. #9
    Join Date
    Aug 2005
    Location
    Sweden
    Beans
    395
    Distro
    Ubuntu

    Re: run a basic command from webpage

    Hmm yes it maybe is that way
    I have now read a little about suexec, not so hard to install but also not so easy if you already have a apache server running. I did only find if I going to set up a new apache server with all that.

    I maybe going to reinstall everything again, this is just a trying and error server right now.

    But if I just have to add www-data access to \dev\video0 I can try that first?
    Or is that a bad idea?

    /Update
    I going to try this guide
    http://x10hosting.com/forums/vps-tut...-easy-way.html

    but I going to have my www in /var/www and the CGI in /usr/lib/cgi-bin
    Last edited by cazz; November 20th, 2012 at 07:19 PM.
    Cazz

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •