diff options
| author | Artyom V. Poptsov <poptsov.artyom@gmail.com> | 2016-12-18 10:22:13 +0300 |
|---|---|---|
| committer | Artyom V. Poptsov <poptsov.artyom@gmail.com> | 2016-12-18 10:22:13 +0300 |
| commit | b11ac0a03deeff6d729219ad71bbd9e10e0d0d20 (patch) | |
| tree | a2b898c1f5de66ad72c4cb5549ed327a33bda200 /modules | |
| parent | shell.scm: Use (ice-9 regex) (diff) | |
| download | guile-ssh-b11ac0a03deeff6d729219ad71bbd9e10e0d0d20.tar.gz | |
shell.scm (fallback-pgrep): Add 'make-command' procedure
* modules/ssh/shell.scm (fallback-pgrep): Add 'make-command' procedure.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ssh/shell.scm | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/modules/ssh/shell.scm b/modules/ssh/shell.scm index 504c1f8..f812515 100644 --- a/modules/ssh/shell.scm +++ b/modules/ssh/shell.scm @@ -86,25 +86,28 @@ Return two values: a check result and a return code." "Guile-SSH implementation of 'pgrep' that uses pure bash and '/proc' filesystem. Check if a process with a PATTERN cmdline is available on a NODE. Return two values: a check result and a return code." + (define (make-command ptrn) + (format #f "\ +echo ' +for p in $(ls /proc); do + if [[ \"$p\" =~ ^[0-9]+ ]]; then + name=$(cat \"/proc/$p/status\" 2>/dev/null | head -1); + if [[ \"$name\" =~~ Name:.*guile ]]; then + cmdline=$(cat \"/proc/$p/cmdline\"); + if [[ \"$cmdline\" =~~ ~a ]]; then + exit 0; + fi; + fi; + fi; +done; +exit 1; +' | bash +" ptrn)) + (let ((ptrn (string-append (regexp-substitute/global #f " " pattern 'pre "?" 'post) ".*"))) - (rexec session - (string-append - "echo '" - "for p in $(ls /proc); do" - " if [[ \"$p\" =~ ^[0-9]+ ]]; then" - " name=$(cat \"/proc/$p/status\" 2>/dev/null | head -1);" - " if [[ \"$name\" =~ Name:.*guile ]]; then" - " cmdline=$(cat \"/proc/$p/cmdline\");" - (format #f " if [[ \"$cmdline\" =~~ ~a ]]; then" ptrn) - " exit 0;" - " fi;" - " fi;" - " fi;" - "done;" - "exit 1;" - "' | bash")))) + (rexec session (make-command ptrn)))) (define (command-available? session command) "check if COMMAND is available on a remote side." |
