Crmgo Blog

PHP script for creating and running a bash file

PHP script for creating and running a bash file

<?php //#$dir_search=$_GET['dir']; $name_search=$_GET['name']; //path and the file itself $file="search.sh"; //if the file doesn't exist... then //if( !file_exists($file)) { $fp = fopen($file, "w"); // ("r" - read, "w" - create, "a" - append to text), we create the file fwrite($fp, "#!bin/bash\n grep -lr '".$name_search."' ./…

PHP script for creating and running a bash file

<?php
//#$dir_search=$_GET['dir'];
$name_search=$_GET['name'];
//path and the file itself
$file="search.sh";
//if the file does not exist... then
//if( !file_exists($file)) {
$fp = fopen($file, "w"); // ("r" - read "w" - create "a" - append to text), we create the file
fwrite($fp, "#!bin/bash\n grep -lr '".$name_search."' ./ > ok.txt");
//fwrite($fp, "grep -lr '".$name_search." ".$dir_search." > ok.txt");
fclose ($fp);
exec ("sh ".$file);
//}

?>

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.

Categories: PHP