在MAC上還沒發現xshell一樣的終端工具。不過mac的終端命令,可以寫好多腳本來管理。
首先想到的就是把服務器IP及密碼使用shell管理起來,以便下次登錄的時候不用在重新輸入,或者只輸入代號就行。但是在寫的時候發現ssh 是不支持密碼參數的,不過找到sshpass 這個是可以的。
首先安裝sshpass
cmd:~ dongjunjie$ brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb ######################################################################## 100.0% xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Error: sshpass cannot be built with any available compilers. Install GNU's GCC brew install gcc cmd:~ dongjunjie$ brew install gcc ==> Installing dependencies for gcc: gmp, isl, mpfr, libmpc ==> Installing gcc dependency: gmp xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Error: Failure while executing: git config --local --replace-all homebrew.private true cmd:~ dongjunjie$ xcode-select --install xcode-select: note: install requested for command line developer tools cmd:~ dongjunjie$ brew install gcc ==> Installing dependencies for gcc: gmp, isl, mpfr, libmpc ==> Installing gcc dependency: gmp ==> Downloading https://homebrew.bintray.com/bottles/gmp-6.1.2_2.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring gmp-6.1.2_2.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/gmp/6.1.2_2: 18 files, 3.1MB ==> Installing gcc dependency: isl ==> Downloading https://homebrew.bintray.com/bottles/isl-0.19.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring isl-0.19.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/isl/0.19: 66 files, 3.8MB ==> Installing gcc dependency: mpfr ==> Downloading https://homebrew.bintray.com/bottles/mpfr-4.0.1.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring mpfr-4.0.1.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/mpfr/4.0.1: 28 files, 4.6MB ==> Installing gcc dependency: libmpc ==> Downloading https://homebrew.bintray.com/bottles/libmpc-1.1.0.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring libmpc-1.1.0.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/libmpc/1.1.0: 12 files, 353.8KB ==> Installing gcc ==> Downloading https://homebrew.bintray.com/bottles/gcc-8.1.0.high_sierra.bottle.1.tar.gz ######################################################################## 100.0% ==> Pouring gcc-8.1.0.high_sierra.bottle.1.tar.gz 🍺 /usr/local/Cellar/gcc/8.1.0: 1,495 files, 336.1MB cmd:~ dongjunjie$ brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb ######################################################################## 100.0% ==> Downloading http://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz ==> Downloading from https://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/sshpass/1.06 ==> make install 🍺 /usr/local/Cellar/sshpass/1.06: 9 files, 41.6KB, built in 18 seconds cmd:~ dongjunjie$ sshpass Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters -f filename Take password to use from file -d number Use number as file descriptor for getting password -p password Provide password as argument (security unwise) -e Password is passed as env-var "SSHPASS" With no parameters - password will be taken from stdin -P prompt Which string should sshpass search for to detect a password prompt -v Be verbose about what you're doing -h Show help (this screen) -V Print version information At most one of -f, -d, -p or -e should be used
其中有一個小插曲
安裝sshpass 提升沒有gcc 安裝gcc 有出現
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun 錯誤
解決辦法:
終端輸入:xcode-select --install 系統彈出下載xcode,點擊確認,下載完成后即可真(可能下載xcode有關插件)。出現這個錯誤猜想可能是因為我之前安裝過xcode又卸載有關。
然后開始寫腳本進行,之后便比較隨意了
#!/bin/sh sshpass -p "pwd" ssh dongjunjie@10.60.**.**
可以參考 http://tinyhema.iteye.com/blog/2093795