linux错误代码255,linux – ssh脚本返回255错误

在我的代码中,我有以下操作来运行远程脚本.

ssh root@host.domain.com "sh /home/user/backup_mysql.sh"

由于某种原因,它对我保持255.有任何想法吗?

我可以SSH进入盒子很好(无钥匙设置)

远程脚本:

MUSER='root'

MPASS='123123'

MHOST="127.0.0.1"

VERBOSE=0

### Set bins path ###

GZIP=/bin/gzip

MYSQL=/usr/bin/mysql

MYSQLDUMP=/usr/bin/mysqldump

RM=/bin/rm

MKDIR=/bin/mkdir

MYSQLADMIN=/usr/bin/mysqladmin

GREP=/bin/grep

### Setup dump directory ###

BAKRSNROOT=/.snapshots/tmp

#####################################

### ----[ No Editing below ]------###

#####################################

### Default time format ###

TIME_FORMAT='%H_%M_%S%P'

### Make a backup ###

backup_mysql_rsnapshot(){

local DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"

local db="";

[ ! -d $BAKRSNROOT ] && ${MKDIR} -p $BAKRSNROOT

${RM} -f $BAKRSNROOT/* >/dev/null 2>&1

# [ $VERBOSE -eq 1 ] && echo "*** Dumping MySQL Database ***"

# [ $VERBOSE -eq 1 ] && echo -n "Database> "

for db in $DBS

do

local tTime=$(date +"${TIME_FORMAT}")

local FILE="${BAKRSNROOT}/${db}.${tTime}.gz"

# [ $VERBOSE -eq 1 ] && echo -n "$db.."

${MYSQLDUMP} --single-transaction -u ${MUSER} -h ${MHOST} -p${MPASS} $db | ${GZIP} -9 > $FILE

done

# [ $VERBOSE -eq 1 ] && echo ""

# [ $VERBOSE -eq 1 ] && echo "*** Backup done [ files wrote to $BAKRSNROOT] ***"

}

### Die on demand with message ###

die(){

echo "$@"

exit 999

}

### Make sure bins exists.. else die

verify_bins(){

[ ! -x $GZIP ] && die "File $GZIP does not exists. Make sure correct path is set in $0."

[ ! -x $MYSQL ] && die "File $MYSQL does not exists. Make sure correct path is set in $0."

[ ! -x $MYSQLDUMP ] && die "File $MYSQLDUMP does not exists. Make sure correct path is set in $0."

[ ! -x $RM ] && die "File $RM does not exists. Make sure correct path is set in $0."

[ ! -x $MKDIR ] && die "File $MKDIR does not exists. Make sure correct path is set in $0."

[ ! -x $MYSQLADMIN ] && die "File $MYSQLADMIN does not exists. Make sure correct path is set in $0."

[ ! -x $GREP ] && die "File $GREP does not exists. Make sure correct path is set in $0."

}

### Make sure we can connect to server ... else die

verify_mysql_connection(){

$MYSQLADMIN -u $MUSER -h $MHOST -p$MPASS ping | $GREP 'alive'>/dev/null

[ $? -eq 0 ] || die "Error: Cannot connect to MySQL Server. Make sure username and password are set correctly in $0"

}

### main ####

verify_bins

verify_mysql_connection

backup_mysql_rsnapshot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值