PHP - Php And Command Line Tools
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, 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 ? 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 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 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 This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=350801.0 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? 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? 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? 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();
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. 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?
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. 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; (1) how to Create administrative tools for an admin. That logged user has a role admin and he can view to add, edit and delete users (2) Create a class for reading data from database. The class (object) handles getting the data (according to a search data if appropriate) from the database table. (3) To Create a picture collection site where an admin user can add and delete images (4) Add 'Remeber me' (or 'keep me logged' etc.) checkbox to the login feature Chrome? Edge? Other? Had a bad experience with Edge. If development tools make one better than the other - what tools? And if you are using PHPStorm maybe the choice of browser is less important? No? Edited June 26 by sen5241bHi Professionals
I am currently going through the process of grading my website in MOZ tools and getting over 2000 URLs to crawl errors
The url I have is currently
www.myurl.com.au/hotel_details.php?hotel_id=358705¤cy_code=AUD&q=%27%3A%2F%2Fwww.travelnow.com%2Ftemplates%2F451536%2Fhotels%2F358705%2Foverview%3Flang%3Den%26amp%3Bcurrency%3DAUD%26amp%3BstandardCheckin%3D12%2F17%2F2014%26amp%3BstandardCheckout%3D12%2F18%2F2014%26amp%3BroomsCount%3D1%26amp%3Brooms[0].adultsCount%3D2%27&price=149&totlday=1 How or where would I go about re-writing this I am not a professional with PHP and I have never done anything like this beforeThanks in advance hello dear php-experts good day
well at the moment i try to figure out how to test the healthy of my harddrive.
How do I use SMART tools to check on my notebooks hard drive? That is the question of the day for me. i want to run a SMART-Test on my notebook to test the harddrive. i have opensuse 13.1 on the machine: and the SMART-Tools are installed. SMART (Self-Monitoring, Analysis, and Reporting Technology) is a technology included in most hard drives today. Short test: According to the documentation, this command can be given during normal system operation (unless run in captive mode). i can run the test: smartctl --test=short /dev/sda1 see here what happens: martin@linux-70ce:~> su Passwort: linux-70ce:/home/martin # smartctl --test=short /dev/sda1 smartctl 6.2 2013-07-26 r3841 [i686-linux-3.11.10-25-desktop] (SUSE RPM) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION === Sending command: "Execute SMART Short self-test routine immediately in off-line mode". Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful. Testing has begun. Please wait 2 minutes for test to complete. Test will complete after Tue Jan 20 00:29:16 2015 Use smartctl -X to abort test. linux-70ce:/home/martin # hmm - this seems to be a short (quick ) test. But i have to wait to see the results. Question: do they come to the terminal - are they are shown in the terminal? btw: i also can run the Long Test: The long test can also be run on a live system, and will do a lot deeper testing on the device, however it will take significantly longer to finish. smartctl --test=long /dev/sda smartctl well - how can i run tests on all the partitions: is this possible to do this with only one single step? cfdisk (util-linux 2.23.2) Festplatte: /dev/sda GrM-CM-6M-C~_e: 320072933376 Bytes, 320,0 GB KM-CM-6pfe: 255 Sektoren pro Spur: 63 Zylinder: 38913 Name Flags Part. Typ Dateisystemtyp [Bezeichner] GrM-CM-6M-C~_e (MB) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- PrimM-CM-$re Freier Bereich 164,63 * sda4 PrimM-CM-$re LVM2_member 1990,20 * sda2 PrimM-CM-$re LVM2_member 21475,89 * sda5 NC Logische swap 2155,88 * sda6 NC Logische ext4 21475,89 * sda7 NC Logische ext4 272799,63 * Pri/Log Freier Bereich 10,84 * but what can i do if i want to Get it all: there are options to do that - getting it all: The next and last command will output all the information the drive can possibly give. In the response below I have selectively removed a lot of output because there is a lot information to go through. My main point is the command and something I will get to in just a second. smartctl -a /dev/sda Device Mode since the harddrive has differnet partitions - the question arises: how to test all at once? question: which way to get the drive tested in one single step are there options to do that - getting it all in a single command. look forward to any and all hints and help greetings |