From 3c5630327ad9ad26a915b340f72c2096adc5f859 Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Mon, 2 Dec 2024 06:02:09 +0900 Subject: [PATCH] New example using ssh --- README.md | 55 ++++++++++++++++++++++++++--------------------- example.lsp | 61 +++++++++++++++++++++++++++++------------------------ 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 8724929..b5d9322 100644 --- a/README.md +++ b/README.md @@ -5,34 +5,41 @@ Lispect - It runs on Windows 10 and later, and Linux - The script is written in the subset of [ISLisp] ([gmnlisp]) -```example.lsp -(if (equal (getenv "OS") "Windows_NT") - (spawn "cmd.exe" "/k" "set PROMPT=$$$S") - (spawn "bash")) +**example.lsp** -(defglobal ctrlc (create-string 1 (convert 3 ))) +```example.lsp (block main - (while t - (expect* - ("xxx" - (send ctrlc) - (expect "$ ") - (sendln "exit") - (return-from main nil) - ) - (("yyy" "zzz") - (send ctrlc) - (expect "$ ") - (sendln 'interval 200 "echo test") - ) - (10 ; timeout second - (send ctrlc) - (expect "$ ") - (sendln "exit") - (return-from main nil) - ) + (if (< (length args) 2) + (progn + (format (error-output) "Usage: ./lispect example.lsp HOSTNAME PASSWORD~%") + (return-from main nil) ) ) + (defglobal host (car args)) + (defglobal password (cadr args)) + + (spawn "ssh" host) + (expect* + ("[fingerprint])?" + (sendln "yes") + (expect "password: ") + (sendln password) + ) + ("password: " + (sendln password) + ) + ("Connection refused" + (return-from main nil) + ) + (30 + (format (error-output) "TIME OUT~%") + (return-from main nil) + ) + ) + (expect "$ ") + (sendln "echo YOU CAN CALL SOME COMMAND HERE") + (expect "$ ") + (sendln "exit") ) ``` diff --git a/example.lsp b/example.lsp index a28c60a..fd1f322 100644 --- a/example.lsp +++ b/example.lsp @@ -1,28 +1,33 @@ -(if (equal (getenv "OS") "Windows_NT") - (spawn "cmd.exe" "/k" "set PROMPT=$$$S") - (spawn "bash")) - -(defglobal ctrlc (create-string 1 (convert 3 ))) -(block main - (while t - (expect* - ("xxx" - (send ctrlc) - (expect "$ ") - (sendln "exit") - (return-from main nil) - ) - (("yyy" "zzz") - (send ctrlc) - (expect "$ ") - (sendln 'interval 200 "echo test") - ) - (10 ; timeout second - (send ctrlc) - (expect "$ ") - (sendln "exit") - (return-from main nil) - ) - ) - ) - ) +(block main + (if (< (length args) 2) + (progn + (format (error-output) "Usage: ./lispect example.lsp HOSTNAME PASSWORD~%") + (return-from main nil) + ) + ) + (defglobal host (car args)) + (defglobal password (cadr args)) + + (spawn "ssh" host) + (expect* + ("[fingerprint])?" + (sendln "yes") + (expect "password: ") + (sendln password) + ) + ("password: " + (sendln password) + ) + ("Connection refused" + (return-from main nil) + ) + (30 + (format (error-output) "TIME OUT~%") + (return-from main nil) + ) + ) + (expect "$ ") + (sendln "echo YOU CAN CALL SOME COMMAND HERE") + (expect "$ ") + (sendln "exit") + )