1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#!/bin/sh
# $Id: csp_sucp,v 1.7 2006-12-12 09:29:16 joostvb Exp $
# $Source: /cvsroot/caspar/caspar/caspar/script/csp_sucp,v $
#
# csp_sucp - mix scp with sudo
#
# usage:
# csp_sucp file [user@]host dir [su-user]
#
# examples:
# csp_sucp fstab rms@bilbo /etc
# csp_sucp trailer.txt monty-python commit/trailer.txt list
#
# warning:
# csp_sucp won't prevent the given password from being echoed!
#
if test -z "$3"
then
echo "usage: csp_sucp file [user@]host dir [su-user]"
exit 1
fi
# command line argument overrules environment variable
test -n "$CSP_SUCP_USER" && opt_u="$CSP_SUCP_USER"
test -n "$4" && opt_u="-u $4"
# first make sure our sudo-timestamp is fresh
ssh -T $2 sudo -v
# now run sudo: we won't be prompted for a password; and
# can use stdin for our data
exec ssh $2 "sudo $opt_u sh -c \"cat - > $3/$1\"" < $1
|