troubleshooting Question

Read mysql record from bash/php

Avatar of projects
projects asked on
PHPMySQL ServerShell Scripting
12 Comments1 Solution523 ViewsLast Modified:
Hopefully, I've provided everything needed.
I am looking for a solution (the code) which picks up a variable on mysql which in turn is used by the bash script to enable or disable a test.

This is the bash side;
function band_test()
        BAND_TIME="$(date +"%F %T")"
        CSTATS=`curl -w '%{speed_download}\t%{time_namelookup}\t%{time_total}\n' -o /dev/null -s`
        BITSPS=`echo $CSTATS | awk '{print $1}' | sed 's/\..*//'`
        DNS_TIME=`echo $CSTATS | awk '{print $2}'`
        TOTAL_TIME=`echo $CSTATS | awk '{print $3}'`
        $CURL -F function=band_test -F band_time="$BAND_TIME" -F bitsps="$BITSPS" -F dns_time="$DNS_TIME" -F total_time="$TOTAL_TIME"

This is the php side;
                        elseif ($_POST['function'] === 'band_test') {
                                 mysql_query('INSERT INTO bandwidth_check ( band_time, bitsps, dns_time, total_time, client_id ) VALUES ("' . $_POST['band_
time'] . '","' . $_POST['bitsps'] . '","' . $_POST['dns_time'] . '","' . $_POST['total_time'] . '","' . $clientid . '")' )
                or die('Query failed: ' . mysql_error());

The client_id mentioned is found by the php code when the remote script connects. I run the script on several workstations which is why I need this id to give each their own records.

I need to read the 'bandwt' field for a 0 or a 1 in the 'clients' table. Return the value to the script so that function band_test is not run if the result is a 0 and run if the result is a 1.

The reason for this is because on some of our networks, I am not allowed to run bandwidth tests while on others I am and I am using one script to do it all.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros