I am trying to pass parameters to command line and get the values using getopt() function. It works fine when I use
php file.php -a arg
But it does not show any value when I use
yiic shell file.php -a arg
I think I am using the incorrect syntax but I didn't get any proper result when I googled for the correct answer.
Any help will be appreciated.
Thanks in advance!
You should use the name of your command instead of the file name. For example, if you have a MyCommandNameCommand class that extends from CConsoleCommand you have to execute the following command from the command line:
yiic shell mycommandname arg1 arg2 ...
Hope it helps.
Well you just have to create a Yii command.
Check this out:
http://www.yiiframework.com/doc/guide/1.1/en/topics.console
In order to create your own command with custom parameters, it should be quite easy, following this SitemapCommand example:
http://www.yiiframework.com/doc/guide/1.1/en/topics.console#console-command-action
Why are you trying to use parameters in yiic shell command? This is a special command that as far as I can see it takes only one parameter. You can see the core file at framework\cli\commands\ShellCommand.php, but again I do not understand why are you messing with this command.
>> yiic help shell
USAGE
yiic shell [entry-script | config-file]
DESCRIPTION
This command allows you to interact with a Web application
on the command line. It also provides tools to automatically
generate new controllers, views and data models.
It is recommended that you execute this command under
the directory that contains the entry script file of
the Web application.
PARAMETERS
* entry-script | config-file: optional, the path to
the entry script file or the configuration file for
the Web application. If not given, it is assumed to be
the 'index.php' file under the current directory.
Related
I'm developing a code which uses ldap_search Shell Script Command for extracting user information from Active Directory using user id and by proper LDAP Server Authentication. I am getting accurate result from ldap_search script.
But, whenever I put the shell script inside exec or shell_exec PHP command, I'm not getting anything.
All the other shell scripts are working fine with the help of PHP exec command except ldap_search.
Is there some additional task left for me to do?
Is ldap_search and exec/shell_exec not compatible with each other?
You must use echo exec('your command or script');
Make sure to have permissions to run it. I mean, the web user must have permissions to execute that.
May seem obvious, but I think your failure is in something basic like this. You must put echo to show the result of the command.
EDIT After reading your new comments about it and using that new info... I saw you are trying to redirect the output to a file... but maybe you have 2 different problems.
Have the user which is executing php (usually www-data) permission to write on the folder where the php is?
Your code has quotes inside quotes that must be escaped using . Try this:
<?php exec("ldapsearch -x -v -h 'LDAP://server' -p '389' -D 'uid=\"domain_user_id\",ou=users,ou=internal,o=\"organization\"' -w 'domain_password' -b 'ou=users,ou=internal,o=organization' 'uid=person's_user_id' >> result.txt"); ?>
So you don't need echo if you want the output in a file. And the redirection >> can be inside the command executed, not in php.
Remember that > replaces de file and what you have >> add at the end of the file.
I have a problem figuring out how make my command work, because I only have access via ftp.
The action is pretty simple:
public function actionRun($action = "default") {
$this->xml = simplexml_load_file('db.xml');
return $this->{$action}(); // executes the default() method
}
All I need is to somehow execute the php index.php mycommand run, but I'm lost as to how. This command should only be run once in the life of the whole app.
My question is, is it possible to run such a command? Maybe somehow invoke it through php?
Yii command line command are designed to run through Yii.
$ cd protected
$ ./yiic --help
$ ./yiic mycommand
If you only have ftp access, you may be out of luck, and will have to use some workaround, for example running a cron job, or creating a web page that invokes the last command in the code sample I provided.
echo exec('/my_yii_dir/protected/yiic mycommand');
I need to create a website that utilizes 2 existing encryption CMD.exe in PHP.
I know that you can use exec() to open CMD file in PHP, but currently my situation is I will need to type like this
D:\temp\userA>d:\myprogfolder\myprog /u r
in my command so that the program will works, in which the D:\temp\userA contains all the file that I need to encrypt and after > is the location of my exe file.
As you can see, they are both in different locations. So for exec(), I don't know how to write a command that can fit into exec() as I try to fill the above line into exec() and it doesn't run.
Is there a way so that I can combine the location of my file that I want to encrypt and exe location into one line and pass it to exec()?
Thank you.
Change the working directory before executing the command:
chdir("D:\temp\userA");
exec("myprogfolder\myprog /u r");
I need your help here.
I wrote one PERL script for PHP application which needs to be run for every 5 mins.
This script will call PHP program, which will fetch data from MySQL DB and will generate a excel report and will mail those reports to specific users.
Every thing seems to be fine when I ran this script manually with the command (perl reports.pl).
But when I set this Perl in a cron tab, nothing works and reports are not getting generated.
Details: perl script path /opt/app/deweb/web/EDI/Microsoft/reports.pl
this script will call PHP program (/opt/app/deweb/web/EDI/Microsoft/reports.php)
content of script
#!/usr/local/bin/perl
use Net::FTP;
use File::Copy;
use POSIX;
#errorreport = `php /opt/app/deweb/web/EDI/Microsoft/reports.php`;
print "#errorreport\n";
exit;
It is working perfectly when running Manually using command - perl reports.pl
No results, when set in CRON:
*/5 7-19 * * * /usr/local/bin/perl /opt/app/deweb/web/EDI/Microsoft/reports.pl
Please note that this crontab is under super user account named webserv and my login is having access to edit under this super user account.
I'm editing this cron tab using command :: sudo -u webserv crontab -e
I would check the following:
Does it run using sudo -u webserv perl reports.pl? If not, fix the problem for the webserv user (permissions or whatever) and it should work via cron too.
Does which perl using your login give you /usr/local/bin/perl? If not, change the path to Perl in crontab to what you got in which perl to fix the problem.
I found myself to be in the same situtation. After trying to find out the reason, I am almost sure about the reason this happens. Crontab does not have the same environment variables as you when running the script. You must be sure about paths. Try for example run your script like /perl-path /path-to-perl-script/script.pl outside the parent directory of the script and I am almost sure that your programm will not find some files. And as you call one php script from the perl script, it's possible to have the same problem with paths to your php script too.
So the solution is to use absolute paths and no relative.
Also at your perl script don't use php but /full-path-to-php for example:
#errorreport = /usr/bin/php /opt/app/deweb/web/EDI/Microsoft/reports.php;
I have a PHP CLI script that I invoke using
php application.php --args etc
However I would like to alias the script so that I can just execute the script without prefixing the command line call with php and having the '.php' extension.
application --args etc
Is this possible? I pressume it is but lack the knowledge or probably the correct terms to search for in Google.
You need to do the thing that Mike Brants says add the next line to your sample.php file
#!/path/to/cli/php
but also you have to do these in linux
chmod +x sample.php
To tell the linux (unix) machine to interprete these file as an excecutable
You could just use a shebang to define the application to use for execution from within the file. So at the beginning of your script you would place something like this:
#!/path/to/cli/php
<?php
// start your PHP here
When executed from command line the OS will know to use the specified PHP CLI application to execute the script. Obviously the path to the PHP CLI excutable will vary based on your system and should be substituted with what I have shown above.
This is more flexible that aliasing IMO, as you don't need to enter an alias for each PHP script you may want to run in such a manner from the command line.
ahah. alias can be added to the .base_profile
http://www.hypexr.org/bash_tutorial.php#alias
Use a so called 'shebang':
In the first line of your script add:
#!/usr/bin/php
where /usr/bin/php is the path to your php cli executable.
That's it !
Even more logical and pleasant (at least my favorite) call is #!/usr/bin/env php
Quote part from the user contributed note on PHP manual it self:
uses "env" to find where PHP is installed: it might be elsewhere in the $PATH, such as /usr/local/bin.