Created
June 25, 2014 01:45
-
-
Save tos-kamiya/faac6f78e98a1d431b8a to your computer and use it in GitHub Desktop.
copy file and do command in remote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# configuration | |
source ./remote_copy_exec.config | |
# check sshass command installed | |
if ! type "sshpass" > /dev/null 2>&1; then | |
echo "command not found: sshpass" | |
exit 1 | |
fi | |
# parse command line | |
doc="usage: remote_copy_exec.sh cmdline..." | |
if [ $# -lt 1 ]; then | |
echo "$doc" | |
exit 0 | |
fi | |
cmdline="$@" | |
cur_dir=`pwd` | |
dir_fname=${cur_dir##*/} | |
# store remote's rsa key to host | |
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no $username@$remote "uptime" | |
# copy local's current dir to server | |
echo "***** copy $dir_fname's contents to remote *****" | |
sshpass -p "$pass" rsync -av -e ssh ../$dir_fname/ $username@$remote:$dir_fname/ | |
# do latex and dvipdfmx | |
echo "***** do command line in remote *****" | |
echo "cd $dir_fname; ( $cmdline ); cd -" | |
sshpass -p "$pass" ssh $username@$remote "cd $dir_fname; ( $cmdline ); cd -" | |
# copy back the pdf file to local | |
echo "***** restore $dir_fname's contents from remote *****" | |
sshpass -p "$pass" rsync -av -e ssh $username@$remote:$dir_fname/ ../$dir_fname/ | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the latest version has gone to a repo: https://github.com/tos-kamiya/remote_copy_exec