summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorArtyom V. Poptsov <poptsov.artyom@gmail.com>2016-12-18 10:22:13 +0300
committerArtyom V. Poptsov <poptsov.artyom@gmail.com>2016-12-18 10:22:13 +0300
commitb11ac0a03deeff6d729219ad71bbd9e10e0d0d20 (patch)
treea2b898c1f5de66ad72c4cb5549ed327a33bda200 /modules
parentshell.scm: Use (ice-9 regex) (diff)
downloadguile-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.scm35
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."