api-shell.texi 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. @c -*-texinfo-*-
  2. @c This file is part of Guile-SSH Reference Manual.
  3. @c Copyright (C) 2017 Artyom V. Poptsov
  4. @c See the file guile-ssh.texi for copying conditions.
  5. @node Shell
  6. @section Shell
  7. @cindex secure shell
  8. A high-level interface to a remote shell built upon @code{(ssh popen)} API.
  9. The procedures described in this section uses GNU Coreutils on the remote side
  10. and may depend on some other packages; see the notes for each procedure.
  11. @deffn {Scheme Procedure} rexec session command
  12. Execute a @var{command} on the remote side. Return two values: list of output
  13. lines returned by a @var{command} and its exit code.
  14. @end deffn
  15. @deffn {Scheme Procedure} which session program-name
  16. Check if a @var{program-name} is available on a remote side. Return two
  17. values: a path to a command if it is found and a return code.
  18. The procedure uses shell build-in command @command{which} on the remote side.
  19. Example:
  20. @lisp
  21. (use-modules (ssh session)
  22. (ssh auth)
  23. (ssh shell))
  24. (let ((s (make-session #:host "example.org")))
  25. (connect! s)
  26. (userauth-agent! s)
  27. (which s "guile"))
  28. @result{} ("/usr/bin/guile")
  29. @result{} 0
  30. @end lisp
  31. @end deffn
  32. @deffn {Scheme Procedure} command-available? session command
  33. Check if a @var{command} is available on a remote machine represented by a
  34. @var{session}.
  35. @end deffn
  36. @deffn {Scheme Procedure} pgrep session pattern [#:full?=#f]
  37. Search for a process with a @var{pattern} cmdline on a machine represented by
  38. a @var{session}. Return two values: a list of PIDs and a return code.
  39. The procedure uses a @command{pgrep} from procps package on the remote side.
  40. @end deffn
  41. @deffn {Scheme Procedure} pkill session pattern [#:full?=#f] [#:signal='SIGTERM]
  42. Send a @var{session} to a process which name matches to @var{pattern} on a
  43. remote machine represented by a @var{session}. Return two values: a pkill
  44. result and a return code.
  45. @end deffn
  46. @deffn {Scheme Procedure} fallback-pgrep session pattern [#:full?=#f]
  47. Guile-SSH implementation of @command{pgrep} that uses pure Bash and
  48. @file{/proc} filesystem. Check if a process with a @var{pattern} cmdline is
  49. available on a machine represented by a @var{session}. Note that @var{full?}
  50. option is not used at the time (the procedure always perform full search.)
  51. Return two values: a check result and a return code.
  52. @end deffn
  53. @deffn {Scheme Procedure} fallback-pkill session pattern [#:full?=#f] [#:signal='SIGTERM]
  54. Guile-SSH implementation of @command{pkill} that uses pure Bash, @file{/proc}
  55. filsystem and Guile itself to kill a process. Note that this procedure won't
  56. work if Guile is missing on a target machine.
  57. Send a @var{signal} to a process which name matches to @var{pattern} on a
  58. remote machine represented by a @var{session}. Return two values: a pkill
  59. result and a return code.
  60. @end deffn
  61. @deffn {Scheme Procedure} loadavg session
  62. Get average load of a host using a @var{session}. Return a list of five
  63. elements as described in proc(5) man page.
  64. Example:
  65. @lisp
  66. (use-modules (ssh session)
  67. (ssh auth)
  68. (ssh shell))
  69. (let ((s (make-session #:host "example.org")))
  70. (connect! s)
  71. (userauth-agent! s)
  72. (loadavg s))
  73. @result{} ("0.01" "0.05" "0.10" "4/1927" "242011")
  74. @end lisp
  75. @end deffn