我想使用ssh登录另一台计算机,然后执行一些简单的bash脚本。
我当前的脚本:
sshpass -p "**********" ssh some@server
while test $# -gt 0; do
case "$1" in
-d) # create a repo with current date
shift
if [ -d ./PCP/$(date '+%Y-%m-%d') ]; then
echo "Directory exists"
else
mkdir ./PCP/$(date '+%Y-%m-%d')
echo "Repo created"
fi
;;
-n) # create a file with name given
shift
if [ -f "./PCP/$1" ]; then
echo "File exists"
else
cd PCP/$(date '+%Y-%m-%d')
touch $1
echo "file created"
fi
shift
;;
-f) # open a connection with the wanted file
shift
vim scp://a81860@search1.di.uminho.pt/PCP/$1
shift
;;
*)
echo "$1 is not a recognized flag!"
return 1;
;;
esac
done
此代码的目的是能够在另一台计算机上编辑文件,我可以通过在该计算机上创建目录和文件来实现。并使用一些标志,我将能够使用scp打开vim。
我已经能够在本地测试脚本,并且可以正常工作,但是当我连接到计算机时,命令将无法像在本地那样执行。