I am having the following requirement:
HTML file:
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Build report</title>
</head>
<!-- <link href="stylesheets/common.css" type="text/css" rel="stylesheet"> -->
<body>
<h1>Select date range</h1>
<form method="post" action="script.php">
Start Date DD-MMM-YYYY: <br />
<input type="text" name="s_date" size="35" />
<br />
End Date DD-MMM-YYYY: <br />
<input type="text" name="e_date" size="35" />
<br /> <br />
<input type="submit" value="Submit" />
<br />
</form>
</body>
script.php file:
Code:
<?php
$s_date = $_POST['s_date'];
$e_date = $_POST['e_date'];
if(empty($s_date ) || empty($e_date )) {
echo "<h2>You must fill in all fields</h2>\n" ;
die ("Click Back to start again.");
}
echo "<h2>You Entered the following information:</h2>";
echo "<b>Starting date:</b><br><br>";
echo $s_date;
echo "<br><br><b>Ending date:</b><br><br>";
echo $e_date;
?>
<?php
// exec ( "var/www/html/reports/bash.sh \"$s_date\" $e_date" );
$output = "<pre>".shell_exec("/var/html/www/reports/bash.sh $s_date $e_date")."</pre>";
echo $output;
?>
bash.sh file:
Code:
#!/bin/bash
#s_date=01-Jan-2019
#e_date=02-Jan-2019
read -p "Enter starting date for concat: " s_date
read -p "Enter ending date for concat: " e_date
if [ "$1" != "" ] ; then
s_date=$1
fi
if [ "$2" != "" ] ; then
e_date=$2
fi
fs=""
i=0
while true ; do
date=$(date +'%d-%b-%Y' --date "$s_date +$i days")
f="auto_test_$(date +'%Y-%b-%d' --date "$s_date +$i days").txt"
((i+=1))
if [ -f $f ] ; then # Check the file exists... maybe some days are missing in this interval?
fs="$fs $f"
fi
if [ "$date" == "$e_date" ] ; then
break
fi
done
cat $fs > "Period $s_date-$e_date"
echo "File "Period $s_date-$e_date" has been generated successfully!";
echo "See file below: "
echo ""
ls -lah | grep 'Period*'
So, the idea is the following:
the user must complete the starting date and ending date from the browser (html file), the dates are being pulled in the script.php which needs to run the bash.sh with the starting date and ending date as parameters.
If I am doing this from the web browser interface, nothing happens and the bash does not run.
But if I am running the bash.sh file on the server using:
Code:
./bash.sh 01-Jan-2019 02-Jan-2019
it works as expected.
What am I doing wrong?