I'm trying to execute a child script in bash through php shell_execute("$command") whose contents are like below.
$command=$_GET['command'];
$op2=shell_exec("$command");
echo "Command $command output is <pre> $op2 </pre>";
On submit I get
Command /path/to/childscript some_pattern 20 username test output is BLANK
basically my child script creates a touch file then send a mail then sleep and then email again and then rm the touch file
hour=`date +%T`
pattern=$1
stime=$2
user=$3
reason=$4
touch ${sdir}/s.${pattern}
echo -e "Snooze activated ! \n Sending mail, please wait."
echo "Snooze started at: $hour for pattern= $pattern by $user for $stime seconds, reason = $4" | mutt a@b.com -s "active"
( echo -e "Snooze was started at: $hour on pattern = $pattern by $user for $stime seconds, buffered contents are below:\n " >> ${sdir}buffer.${pattern} && sleep $stime && rm -rf ${sdir}s.${pattern} && mutt a@b.com -s "Snooze expire" < ${sdir}/buffer.${pattern} && rm -rf ${sdir}/buffer.${pattern})&
Since i was getting blank as my output. I tried running this script by making a cleaner parent trigger script
cat trigger
bash /path/to/childscript some_pattern 20 username testing &
echo "done"
And I simply call this trigger script on submit, which gives me some progress
Command /path/to/trigger output is
done
Snooze activated !
Sending mail, please wait.
I get an email aswell this time. Which means my child script does get called but my commands inside () dont get executed. The reason why last command is written like that is that i need to sure that all those commands occur in sequence only. This is surely some subshell/background problem but I'm stuck how to get this whole script working. Also I would like to run child script directly rather than invoking trigger which in turn invokes child.
My form code, although it looks fine is as below
<div id= "test" >
<form action="/path/to/test.php" >
<form method="post" action="" >
<b>Execute command:</b><br>
<input type="text" name="command">
<input type="submit" value="enter">
<br><br>
</form>
</div>
I'm absolutely new to web devl and have been warned that this can be fatal if someone executes some random command. I agree to it, but only authorised person can get access to this page. Also if this is not possible what would be the way to run this script with appropriate checks.