mirror of
https://github.com/hymkor/lispect.git
synced 2026-08-28 04:46:59 -04:00
example.lsp and README: add error cases
- "Could not resolve hostname" - error catch when ssh is not found - rename variables - password error
This commit is contained in:
@@ -15,36 +15,39 @@ Lispect
|
|||||||
(block main
|
(block main
|
||||||
(if (< (length args) 2)
|
(if (< (length args) 2)
|
||||||
(progn
|
(progn
|
||||||
(format (error-output) "Usage: ~A ~A HOSTNAME PASSWORD~%" $EXECUTABLE_NAME $PROGRAM_NAME)
|
(format (error-output) "Usage: ~A ~A USERNAME@DOMAIN PASSWORD~%" $EXECUTABLE_NAME $PROGRAM_NAME)
|
||||||
(return-from main nil)
|
(return-from main nil)))
|
||||||
)
|
(defglobal account (car args))
|
||||||
)
|
|
||||||
(defglobal host (car args))
|
|
||||||
(defglobal password (cadr args))
|
(defglobal password (cadr args))
|
||||||
|
|
||||||
(spawn "ssh" host)
|
(with-handler
|
||||||
|
(lambda (c)
|
||||||
|
(format (error-output) "ssh is not found~%")
|
||||||
|
(return-from main nil))
|
||||||
|
(spawn "ssh" account))
|
||||||
|
|
||||||
(expect*
|
(expect*
|
||||||
("[fingerprint])?"
|
("[fingerprint])?"
|
||||||
(sendln "yes")
|
(sendln "yes")
|
||||||
(expect "password: ")
|
(expect "password: ")
|
||||||
(sendln password)
|
(sendln password))
|
||||||
)
|
|
||||||
("password: "
|
("password: "
|
||||||
(sendln password)
|
(sendln password))
|
||||||
)
|
(("Connection refused"
|
||||||
("Connection refused"
|
"Could not resolve hostname")
|
||||||
(return-from main nil)
|
(return-from main nil))
|
||||||
)
|
|
||||||
(30
|
(30
|
||||||
(format (error-output) "TIME OUT~%")
|
(format (error-output) "TIME OUT~%")
|
||||||
|
(return-from main nil)))
|
||||||
|
|
||||||
|
(expect*
|
||||||
|
("Permission denied"
|
||||||
(return-from main nil)
|
(return-from main nil)
|
||||||
)
|
)
|
||||||
)
|
("$ "))
|
||||||
(expect "$ ")
|
|
||||||
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
||||||
(expect "$ ")
|
(expect "$ ")
|
||||||
(sendln "exit")
|
(sendln "exit"))
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Install
|
Install
|
||||||
|
|||||||
+20
-17
@@ -1,33 +1,36 @@
|
|||||||
(block main
|
(block main
|
||||||
(if (< (length args) 2)
|
(if (< (length args) 2)
|
||||||
(progn
|
(progn
|
||||||
(format (error-output) "Usage: ~A ~A HOSTNAME PASSWORD~%" $EXECUTABLE_NAME $PROGRAM_NAME)
|
(format (error-output) "Usage: ~A ~A USERNAME@DOMAIN PASSWORD~%" $EXECUTABLE_NAME $PROGRAM_NAME)
|
||||||
(return-from main nil)
|
(return-from main nil)))
|
||||||
)
|
(defglobal account (car args))
|
||||||
)
|
|
||||||
(defglobal host (car args))
|
|
||||||
(defglobal password (cadr args))
|
(defglobal password (cadr args))
|
||||||
|
|
||||||
(spawn "ssh" host)
|
(with-handler
|
||||||
|
(lambda (c)
|
||||||
|
(format (error-output) "ssh is not found~%")
|
||||||
|
(return-from main nil))
|
||||||
|
(spawn "ssh" account))
|
||||||
|
|
||||||
(expect*
|
(expect*
|
||||||
("[fingerprint])?"
|
("[fingerprint])?"
|
||||||
(sendln "yes")
|
(sendln "yes")
|
||||||
(expect "password: ")
|
(expect "password: ")
|
||||||
(sendln password)
|
(sendln password))
|
||||||
)
|
|
||||||
("password: "
|
("password: "
|
||||||
(sendln password)
|
(sendln password))
|
||||||
)
|
(("Connection refused"
|
||||||
("Connection refused"
|
"Could not resolve hostname")
|
||||||
(return-from main nil)
|
(return-from main nil))
|
||||||
)
|
|
||||||
(30
|
(30
|
||||||
(format (error-output) "TIME OUT~%")
|
(format (error-output) "TIME OUT~%")
|
||||||
|
(return-from main nil)))
|
||||||
|
|
||||||
|
(expect*
|
||||||
|
("Permission denied"
|
||||||
(return-from main nil)
|
(return-from main nil)
|
||||||
)
|
)
|
||||||
)
|
("$ "))
|
||||||
(expect "$ ")
|
|
||||||
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
||||||
(expect "$ ")
|
(expect "$ ")
|
||||||
(sendln "exit")
|
(sendln "exit"))
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user