分类:
2010-03-24 16:03:07
#!/bin/bash## push a user's ssh pubkey to a remote server#
usage(){cat <Usage: $(basename $0) [-h host] [-u user] [-s service] [-x start|stop|status] EOF1}
usage_service(){cat <Usage: {gf|tc|nginx|openvpn|svc|nrpe|nagios|dess|[cs lobby .....](gameserver)} EOF1}
find_command(){ awk "/$service/&&/$user/&&/$host/ {print \$4}" $serverstart}while [ -n "$1" ]; do case "$1" in "-u"|"--user") shift user=$1 shift ;; "-h"|"--host") shift; host=$1 shift ;; "-s"|"--service") shift; service=$1 shift ;; "-x"|"--operform") shift; operation=$1 shift ;; "-H"|"--help") usage exit 0 ;; "-q"|"--quiet") quiet=1 shift ;; *) echo "Error: Invalid argument" usage exit 1 ;; esacdone
[ -z "$host" -o -z "$user" -o -z "$service" ] && usage && exit 1
workdir=/home/zn/binserverstart=$workdir/serverstart.txtcommand=`find_command`[ $? -ne 0 ] && echo "Error: without this service" && usage_service && exit 1
myrootkey=/srv/key/sshkey/zn
cmdline="$command $operation"echo "Will run the following command on host '$host':"#echo $cmdline
if [ -z "$quiet" ]; then echo "Continue(y/n)?" read confirm [ "$confirm" != "y" ] && echo "Canceled!" && exit 2fi#echo $hostRCMD="ssh -i $myrootkey $user@$host"
$RCMD "$cmdline && echo "$service $operation .........ok""
阅读(598) | 评论(0) | 转发(0) |