Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display output from Unix shell script as it happens

    Hi,

    I am trying to write an interface using php that will allow users to execute various shell scripts on our Unix server from a single internal web page.

    Is there any way to have the output from these scripts print to my page as it happens. Some scripts can take up to 1/2 an hour to run, so it is not really ideal to wait until they finish processing, then display the output in one hit.

    Ideally I would have a text box that keeps updating it's contents periodically until the script finishes.

    Cheers

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    you can use output buffering , though you may need to actually open a pipe and talk to it , look in the manual for ob_start & ob_end_flush + proc_open & proc_close (good example in proc_open)

    but the reason I posted was to say that your idea is an incredibly bad one , however safe you try to make it, to be usable/useful it has to be unsafe ! , if your users need the shell then why not look at SSH etc ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply,

    This page is only available from within our Domain and I was planning on using a single secure directory to store all the runnable scripts.

    Any physical output (.csv files etc) will be available for download via a link, and avaliable to specified users only.

    It would just be nice to be able to let the user see the progress messages from the shell scripts while they wait.

    Do you think ssh might be more than I need?
    I can live without the output until the end of a system() call if it is going to open up unnecessary risks.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Hi , sorry but I think I got the wrong end of the stick , I thought you were allowing users to pass shell commands via the browser to be executed by exec() etc , I see now that you mean you have some existing pre-written shell scripts that you simply want a browser interface to run, in which case the nonsense above is exactly that !

    ok how to check the progress of the scripts.. do the scripts have any output while running ? in which case the example at http://www.php.net/proc_open may be useful as you can read the output & flush() to the browser , if not (and I see the script creates other files) you can check the size of those files periodically , that usually means 2 scripts though , 1 to spawn the system call & the other to track the status of the created file, so you would have to say $pp=popen('/usr/blah/scripts/blah.sh','r'); the shell script then check the filesize of the created files and keep flush()ing

    If I can think of a better example I will
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweet, that proc_open looks like the business.
    The output I want to display is from echo statements within the shell scripts, so should be fairly straightforward after looking at that link you provided.

    Thanks a lot for the help


  •  

    Posting Permissions

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