Last active
January 11, 2023 20:55
-
-
Save iuioiua/f68c61ee0149cb7794c80ba8bbbf36e5 to your computer and use it in GitHub Desktop.
Run an SSH command on a remote machine via Plink in Deno.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { $ } from "https://deno.land/x/dax@0.23.0/mod.ts"; | |
export interface PlinkInit { | |
host: string; | |
username: string; | |
password: string; | |
command: string; | |
} | |
/** | |
* @example | |
* ```ts | |
* import { plink } from "./mod.ts"; | |
* | |
* await plink({ | |
* host: "192.168.0.1", | |
* username: "root", | |
* password: "password", | |
* command: "echo 1", | |
* }); | |
* ``` | |
*/ | |
export async function plink(init: PlinkInit): Promise<string> { | |
return await $`plink ${init.username}@${init.host} -pw ${init.password} "${init.command}"` | |
.stdin("echo y") | |
.text(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment