第一拷貝和scp
文件過這樣的scp /tmp/sshf.sh $SERVER:~
這將會把你的腳本sshf.sh
在你的home目錄上$SERVER
那麼你可以ssh
到機器並運行它ssh $SERVER cat ~/sshf.sh
作爲一個叫做copy_run_stay.sh
腳本與sshf.sh
包含echo hello
將如下所示:
#!/bin/bash
# get server name as argument to script
SERVER=$1
script='sshf.sh'
# copy script to server
scp $script $SERVER:~
# run script on server
ssh $SERVER cat ~/sshf.sh
# stay on server
ssh $SERVER
而且會產生:
# run the script on laptop
laptop $ ./copy_run_stay.sh
# sshf.sh gets copied to server and ran
server $ hello
# we are still on the server
server $