I am trying to display the output of a bash script to a div on my webpage. But when i load the page nothing appears. Here is what I have so far.

Jquery ajax function. Discon is the name of the div the info is supposed to be appearing in.

$(document).ready(function() {
    $.ajax({
            type: "POST",
            url:  "discon.php",
            data: "Discontinuities",
            success: function(data) {
            $('#discon').html(data)
            }
    });
 });

Here is my php to take what is in the jquery. Note the commented out parts are places where i was trying different options in php. I have tried several and nothing seems to work.

<?php

 echo passthru('/opt/bin/enc_current_test');

//$discon = exec('/opt/bin/enc_current_test', $o, $r);
//if ($r != 0){
//      print 'Error running command';
//      exit($r);
//}
//else{
//      print implode("\n", $o);
//}

?>

I have another bash script that is displaying to the same page in a different Div and it works fine so my question is why is this one giving me a problem. Here is the bash script.

#!/bin/bash

while [ true ]
do
    counter=0

    clear
    date

    dir=/test/`date "+%Y/%m/%d"`

    cd $dir
    echo Writing On: `pwd`

            for i in `ls`
            do
                    if [ -n "$(ls -l $i/* | grep `date "+ %k:%M"`)" ];
                    then
                            echo $i
                            let "counter+=1"
                    fi
            done
    echo
    echo "Total Current Streams: "
    echo $counter
    sleep 60
    clear
done

I am thinking it is because the script sleeps for 60 seconds, but i added the tag in my html to refresh the page at that same interval and it still does not work. Any idea as to why this script would not display? Kind of at a loss at this point. Thanks for any replies.

share|improve this question
    
You say discon is the name of the div, but your jQuery selector is $("#discon"). Sure you haven't got the name/id mixed up? – Osiris Nov 14 '12 at 10:48
up vote 1 down vote accepted

your bash script runs infinite loop

while [ true ]
do
...
done

the web server keeps waiting the answer from script and doesn't send it to client (browser)

try to comment while loop and sleep command in bash script

also i guess you don't want to see extra characters written by clear command, so comment them too

#!/bin/bash

#while [ true ]
#do
    counter=0

#    clear
    date

    dir=/test/`date "+%Y/%m/%d"`

    cd $dir
    echo Writing On: `pwd`

            for i in `ls`
            do
                    if [ -n "$(ls -l $i/* | grep `date "+ %k:%M"`)" ];
                    then
                            echo $i
                            let "counter+=1"
                    fi
            done
    echo
    echo "Total Current Streams: "
    echo $counter
#    sleep 60
#    clear
#done
share|improve this answer
    
Thanks alot i thought it might have to do with either the loop or the sleep variable. This solved my problem. – Thrawn Nov 20 '12 at 0:23

Remove the echo before the passthru().

passthru() does not return anything (void), it outputs directly. So your current statement echos void.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.