PHP - Moved: Av Command Line Scan Help
This topic has been moved to Other Web Server Software.
http://www.phpfreaks.com/forums/index.php?topic=350801.0 Similar TutorialsHi, I'm having a weird issue when I try to run PHP scripts from the command line on my server. I'm trying to just run a very simple script to test it out: #!/usr/bin/php-cgi -q echo "Hello terminal\n"; And I get the following error in the terminal.. Code: [Select] Error in argument 1, char 3: option not found Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f <file>] php-cgi <file> [args...] When I try taking out the quiet (-q) parameter, I get the following error.. Code: [Select] -bash: ./socket_server.php: /usr/bin/php-cgi^M: bad interpreterNo such file or directory As you can see, in the second example, a rogue "^M" was appended to the end of the first line of my socket_server.php file. What does ^M correlate to? I realize it is a character code for something that can't be represented with an actual character, but I don't know what it is, and I'm not sure why it is being appended to the end of my first line. My assumption is that this is happening in the first example too, which is why I get the "error in argument 1" message, since undoubtedly -q^M is an invalid argument... Any help is greatly appreciated! nethnet Hi.. I have a php file where i have only one line which says header('Location: index.php'); How do i run this php file in the terminal on fedora 14? Thanks, Rohit Hi, I am trying to use php to pass some commands to my linux box.From my webpage I am using the shell_exec function which is working OK but for some administrative tasks in linux I must have root access. As I am sending the commands from the webpage the apache user is used and so I am not allowed to do several tasks. I have also tried to use a bash script to pass the commands but with no result. Any ideas ? I am trying to execute a command line tool, but am having a problem adding a variable to the line. Here is the code Code: [Select] $filename = "devices.txt"; $handle = fopen($filename, 'r'); while (!feof($handle)) { $devices = fgets($handle, 4096); $query = 'ipmitool -I lanplus -H 192.168.1.1 -U admin -P adminpass sdr list'; passthru($query); } flcose($handle); On this line I don't want to have the IP manually added like so. Code: [Select] $query = 'ipmitool -I lanplus -H 192.168.1.1 -U admin -P adminpass sdr list'; Instead I want to be able to insert the $devices variable which contains the values from the text file so it would look something like this: Code: [Select] $query = 'ipmitool -I lanplus -H $devices -U admin -P adminpass sdr list'; Problem is the command line tool does not run this way. How do I properly add the $devices variable so the command line tool ipmitool will run with its value? Thanks, hey guys m using STDIN as input stream in php command line my problem is that some time i get this error Warning: fgets(): supplied argument is not a valid stream resource in D:\myquery \test.php on line 16 $number=fgets(STDIN); anyone knows solution Hello everyone I have a question? I run a PHP script loads about 200 calls simultaneously on Linux environment, so my question is what is best way to run a command line As an example php-f example.php or make it through the apache example "curl http://localhost/example.php" Thank you woren Hi guys, I'm trying to run a php script from command line in linux. I installed xampp for linux a.k.a lampp so typing php /path/to/file.php Just brings up a message saying I need to install php. Whats the correct way to do this? can anyone help me with an overwhelming problem ? I want to use this command in the php curl code. curl -v --data "WSCommunityStringRW?2=1200ve50set&Submit=Submit" http://10.2.3.111/Forms/SnmpCommunityString -u "admin:a1s2d3" --anyauth Hi, suppose I want to write a PHP script that checks whether a valid email address exists or not. There are a number of GUI-based tools to verify this, but is there any command line tool to do the same so that I can use PHP to capture the output? hello dear php-experts how to testrun a drive with command-line? note: i had several blank screens during the last week does this somewhat have to do with the hard-drive? which tests can be done? Hello all
I'm new to this forum. I've been struggling on this problem for a few days now.
I’m writing a script to automatically push code to a git server. exec(‘git config user.name "’ . $userName . ‘"’); exec(‘git config user.email "’ . $userEmail . ‘"’); exec('git checkout -b ’ . $branch); exec(‘git add --all’); exec(‘git commit -m "’ . $message . ‘"’); exec('git push origin ’ . $branch);
When running the last command, the script stops and asks for a user name, then a password. I tried other forums, searching the net. I'm frustrated...
Thanks in advance. So, I'm trying to read a file from a different filepath than the current working directory.
I have some simple PHP like this :
<?php $input_map = "readfile.php"; $map_contents = file_get_contents($input_map); echo $map_contents."<br />\n"; ?>And this'll work fine because it's in the same directory but if I try to set $input_map = "/home/...", the browser will return an empty string. This script will work from the command line though. So how do I get file_get_contents() to read from the server's file structure instead of just the working directory? Edit : For example, this will not work through the browser : <?php $input_map = "/home/..."; $map_contents = file_get_contents($input_map); echo $map_contents."<br />\n"; var_dump($map_contents); ?> Edited by MutantJohn, 21 January 2015 - 06:35 PM. I would like to update the DB when a service ends and thought about doing so in the destructor, but I did not make much progress. Then tried using pcntl_signal(), but also didn't get far. Is doing so possible? Thanks /usr/lib/systemd/system/test123.service [Unit] Description=bla After=syslog.target [Service] ExecStart=/usr/bin/php /var/www/testing/__destruct.php [Install] WantedBy=multi-user.target
/var/www/testing/__destruct.php <?php ini_set('display_errors', 1); pcntl_signal(SIGTERM, function() { syslog(LOG_INFO, 'Caught SIGTERM'); die; }); pcntl_signal(SIGHUP, function() { syslog(LOG_INFO, 'Caught SIGHUP'); die; }); pcntl_signal(SIGUSR1, function() { syslog(LOG_INFO, 'Caught SIGUSR1'); die; }); pcntl_signal(SIGINT, function() { syslog(LOG_INFO, 'Caught SIGINT'); die; }); pcntl_signal(SIGABRT , function() { syslog(LOG_INFO, 'Caught SIGABRT '); die; }); /* pcntl_signal(SIGSTOP , function() { syslog(LOG_INFO, 'Caught SIGSTOP '); die; }); */ /* pcntl_signal(SIGKILL , function() { syslog(LOG_INFO, 'Caught SIGKILL '); die; }); */ class Bla { private $bla; public function __construct($bla) { syslog(LOG_INFO, '__construct'); $this->bla = $bla; } public function __destruct() { syslog(LOG_INFO, '__destruct'); } public function start() { $counter=0; $counter2=0; while(true) { $counter++; if($counter>10000000) { $counter2++; $counter=0; syslog(LOG_INFO, '.'); } if($counter2>5) { die('all done!'); } } } } $bla = new Bla('hello'); $bla->start();
No idea how to add a new line so it's easier to read in the terminal. Debugging this way is absolutely horrible.
Edited by Monkuar, 03 December 2014 - 09:06 AM. Hi all, In the process of moving websites off an old win 2008 server and onto a new win 2016 server. I discovered that dns_get_record is failing on the new server. I made a simple test page: $dnsrecs = dns_get_record('google.com'); When i call this as a webpage, it comes back with dns query failed. It comes back instantly, so it's not like it's timing out. But, if i just call the webpage from the command line, it comes back with the dns record. Why would dns_get_record fail when used in a webpage, but work from the command line? I can make outside connections since I was able to send an email to an smtp server. I thought maybe this is a permission issue, but seems odd I'd be able to send an email using php but not do a dns query. Oh, and I have two versions of php installed on this server - 5.4.10 and 7.4.9. The old version is a direct copy from the 2008 server. 7.4.9 is a clean install. Both of them behave the same way. webpage fails, command line works. Also, nslookup works. I also tried switching to using google's name server, but it had no effect on anything. Anyone have any suggestions? I have a PHP file that is executed via batch file very frequently for live updating. This is a sort of "sync" file for reading/writing to a MySQL database. I am able to get it functioning absolutely fine when executed manually via a web browser (and my echo debug lines output the expected information), yet when I run the same PHP file via the command line, it seems to just not be capable of opening any file for reading, so the equivalent variables that are correct when executed on a web browser are blank when echoed through the command line. Is there a different way of handling reading of files when running a php script via the command line, or should it function exactly the same as when run via a browser? For instance: $k = "0"; $line = file("examplefile.log")[$k]; echo $line; This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=326238.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313826.0 Hi hi, CAn anyone tell me why this piece of code doesn't work? Code: [Select] <?php function readDirs($main){ $dirHandle = opendir($main); while($file = readdir($dirHandle)){ if(is_dir($file) && $file != '.' && $file != '..'){ readDirs($file); } else{ echo $file . '<br/>'; } } } $dir = '../../lib'; readDirs($dir); ?> It must show all the files in the directory, but only shows: Code: [Select] . .. technical Hi all. I'm trying to build a dynamic multiple tiered navigation menu that operates on the existence of directories. So far, I have some code that will read through the document root, and one sub level of directories but I'm not sure how to get into the third level of directories. Here's what I have so far... The code: $docroot=scandir($_SERVER['DOCUMENT_ROOT']); unset($docroot[array_search('.',$docroot)]); unset($docroot[array_search('..',$docroot)]); unset($docroot[array_search('php',$docroot)]); unset($docroot[array_search('css',$docroot)]); unset($docroot[array_search('input_forms',$docroot)]); $docroot=array_values($docroot); //Build tier 1 echo "<div class=\"tier\">"; echo "<a href=\"/index.php\">Home</a>"; foreach($docroot as $value1){ if(is_dir($value1)){ $t2=scandir($_SERVER['DOCUMENT_ROOT'] . "/" . $value1); unset($t2[array_search('.',$t2)]); unset($t2[array_search('..',$t2)]); $t2=array_values($t2); $t1[]=$t2; echo "<a href=\"/$value1/\">"; $value1=str_replace("_"," ",$value1); $value1=ucwords($value1); echo $value1; echo "</a>"; } } echo "</div>"; The output: Code: [Select] [it automatically builds the first tier of the menu with some stylesheet definitions and places it here. I did this just for testing purposes.] Array ( [0] => Array ( [0] => bus_mgmt_context.pdf [1] => financial_management [2] => index.php [3] => nav.php [4] => service_level_management [5] => service_portfolio [6] => workforce_management ) [1] => Array ( [0] => element_inventory [1] => index.php [2] => mobile_administration [3] => monthly_bill_review [4] => nav.php ) [2] => Array ( [0] => business_it_requests [1] => change_management [2] => demand_management_context.pdf [3] => index.php [4] => nav.php [5] => project_management [6] => release_management ) [3] => Array ( [0] => availability_management [1] => capacity_management [2] => configuration_management [3] => index.php [4] => nav.php [5] => planning [6] => problem_management [7] => system_planning ) [4] => Array ( [0] => context [1] => input [2] => reports [3] => sop [4] => t3.php [5] => video ) [5] => Array ( [0] => executive_reports [1] => index.php [2] => kpi_index [3] => nav.php ) [6] => Array ( [0] => compliance [1] => hipaa_definitions.pdf [2] => index.php [3] => information_security [4] => nav.php [5] => risk_context.pdf [6] => service_continuity [7] => threat_management ) [7] => Array ( [0] => incident_management [1] => index.php [2] => nav.php [3] => release_management [4] => service_desk [5] => service_requests [6] => supplier_management ) ) |