當我將ssh發送到服務器後,如何從腳本遠程運行一段代碼?不知道它是否可能。在SSH連接後運行一段代碼Bash
ssh "$server" #SSH login
echo Connected to "$serverName"
exec < filelist.txt
while read updatedfile oldfile; do
# echo updatedfile = $updatedfile #use for troubleshooting
# echo oldfile = $oldfile #use for troubleshooting
if [[ ! $updatedfile =~ [^[:space:]] ]] ; then #empty line exception
continue # empty line exception
fi
if [[ ! $oldfile =~ [^[:space:]] ]] ; then #empty line exception
continue # empty line exception
fi
echo Comparing $updatedfile with $oldfile
if diff "$updatedfile" "$oldfile" >/dev/null ; then
echo The files compared are the same. No changes were made.
else
echo The files compared are different.
cp -f -v $oldfile /infanass/dev/admin/backup/`uname -n`_${oldfile##*/}_$(date +%F-%T)
cp -f -v $updatedfile $oldfile
fi
done
[通過bash腳本SSH命令]的可能重複(http://stackoverflow.com/questions/4225652/ssh-commands-via-bash-script) – devnull
問題還要求對[UNIX和Linux](HTTP: //unix.stackexchange.com/q/83228/4667) –
[在SSH中運行多個命令的最簡潔的方法是什麼?](http://stackoverflow.com/questions/4412238/whats-the- CLEARSTEST-way-to-ssh-and-run-multiple-commands-in-bash) – mnagel