uci-utils-ssh/bin/ssh.js

44 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
// third party imports
import Ssh from '../src/ssh'
import to from 'await-to-js'
import logger from '@uci-utils/logger'
import yargs from 'yargs'
const log = logger({appName:'sshu', package:'ssh', bin:'./bin/ssh.js', class:'Ssh', id: 'ssh-binary' })
log.debug({arguments:process.argv, msg:'arguments passed to ssh cli'})
let arg = yargs
.alias('c','config')
.argv
;
(async () => {
const ssh = new Ssh()
arg.c ? log.debug(`loading ssh config file ${arg.c}`) : log.debug('loading ssh default config file')
await ssh.configure(arg.c) // null = default config
log.info(`making connection to ${ssh.opts.host}`)
let [err] = await to(ssh.connect())
if (err) {
log.info({err:err, msg:'unable to connect'})
return err
}
// let cmd = arg._.join(' ')
// console.log(cmd)
// let [err2,res] = await to(ssh.exec(cmd))
// if (err2) {
// log.info({err:err2, command:cmd, msg:'error running command aborting'})
// return
// }
// ssh.close()
// return res
let res = await ssh.shell({cli:true})
log.info({history:res.cmds, msg:'returned from remote shell'})
})().catch(err => {
console.error('FATAL: Failed to Connecct to Remote!\n',err)
})