Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Created June 25, 2014 01:45
Show Gist options
  • Save tos-kamiya/faac6f78e98a1d431b8a to your computer and use it in GitHub Desktop.
Save tos-kamiya/faac6f78e98a1d431b8a to your computer and use it in GitHub Desktop.
copy file and do command in remote
#!/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
@tos-kamiya
Copy link
Author

the latest version has gone to a repo: https://github.com/tos-kamiya/remote_copy_exec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment