-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.phpakefile
33 lines (30 loc) · 992 Bytes
/
shell.phpakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace Shell;
/**
* List the contents of the working directory.
*
* Simply runs a system command and shows its output.
*/
function ls() {
exec('ls', $output);
echo join(PHP_EOL, $output);
}
/**
* Open an SSH connection.
*
* Here, $rest expects arguments that look like options/switches. By default,
* Phpake sees them as invalid options/switches. To make it clear that those
* switches are nothing but multiple string arguments, we put -- before them.
*
* @usage example.com john.doe -- "-o ForwardAgent=yes"
*
* @param string $host A remote host, e.g. example.com
* @param string|null $user A username. Defaults to the current user.
* @param array|null $rest SSH options.
*/
function ssh(string $host, string $user = NULL, array $rest = NULL) {
$command = "ssh $user@$host " . join(' ', $rest);
// Depending on the command, you can also use: passthru($command);
$process = proc_open($command, [STDIN, STDOUT, STDERR], $pipes);
proc_close($process);
}