Php cli application skeleton
- PHP 7.x
- libssh2 library
This cli php script help you do some operations. It contains some base classes like ssh client or preconfigured comfortable (for me) echo class.
If you need do some operations just create some user function in Cli
class.
For example if you want make operations in destination server, you may create
one function like this:
/**
* Check ssh client
*/
private function checkSshCommand(string $server)
{
$this->echo->msg("Try connect to server $server");
$ssh = new Ssh_clien($server);
$this->echo->msg(
$ssh->exec([
"su admin\r",
"cd /home/admin/web",
"dir",
"pwd",
"exit"
])
);
$this->echo->msg('Finish');
}
- connect to destination server as
root
; - login as admin user;
- change directory to
/home/admin/web
- show current derictory;
- logout from admin user to
root
- For creating some special function you need create some method
named like
yourMegaMethodCommand
withCommand
word in the end of name. - If you want send parameters to your method just set var with type and default parameter (if need) like this.
private function checkSshCommand(string $server)
{
//... METHOD BODY
}
- Dont forget add some description for your method.
/**
* Your functions very clear description
*/
private function checkSshCommand(string $server)
{
//... METHOD BODY
}
For running command in cli.php you can view functions help like this:
$ ./cli.php
Hello! This is cli php script for do some operations
USAGE: $cli.php command [--param1] [--param2] [param2Value]
Please use follow commands:
checkSsh:
check ssh client
--server (string)
test:
Testing current utility
--name (string)
--is_required (bool)
--number (int)
--price (float) <4.18>
--color (string) <RED>
test2:
Test 2 some comment
multiple
lines
--name <Ralf>
help:
current help message
man:
Show only one command description
--cmd
or just run method
$ ./cli.php checkSsh --server servername.com
Try connect to server servername.com
domain1.com docs.domain1.com ds.domain1.com m.domain1.com domain2.com
/home/admin/web
Finish