首页 > 编程知识 正文

hadoop远程执行命令,ssh远程执行命令环境变量

时间:2023-05-05 07:48:30 阅读:36565 作者:242

ssh登录远程服务器执行命令文章目录ssh登录远程服务器执行命令前言参数说明脚本源结语

前言

本文主要介绍如何通过ssh登录远程服务器、运行相关命令、获取执行结果以及粘贴脚本源。

参数说明serverIp=$1 #远程IPsshUser=$2 #SFTP用户sshPass=$3 #SFTP密码sshCmd=$4 #远程命令脚本源#!/lywl/bash # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 获取接收参数serverIp=$1 #远程ipshuser=$2#的当前系统日期- yyymmddsysdate=` date ' % y % m % d ' ` #当前系统时间- hhmmss systime 定义app/lapp log file=$ { log path }/ssh cmd _ $ { systime }.log #定义日志函数log () createtime=` date ' % y-% m-% d % h then mkdir _ log=` mkdir-p-m775 $1` if [ $? -ne 0 ] (; thenecho ' [ error ] :目录[ $1]创建故障,please check.' exit 1 fi fi}#检查日志目录CheckDir '${logPath}'# 请检查一下。 ' log ' [ error ] eg : ' log ' [ error ] sh $ { sh name }远程IP ssh用户ssh密码远程命令' exit 1fi# 主函数execute_ssh_cmd (定义的{ local server IP=$1localsshuser=$2localsshpass=$3localsshcmd=$4log _ file=$ { locale ) sed ' s/ $/\"/g ' ` expect eof $ { log _ file } #需要超时时间。 远程命令的执行时间不确定,因此设定为不超时{ send ' yesn ' expect ' * password : ' { send ' $ { ssh pass }n ' } ' * assword No route to host' { send 'IP地址不正确或无法连接到网络。 n' } } expect { 'please try again' { #密码输入不正确。 由于之前未设置超时时间限制,因此必须发送键盘命令Ctrl C退出当前密码03n' } } #获取远程命令的执行结果catchwaitresultexit [ lindex$ $ log '==============远程命令执行日志信息如下===========' cat $ { log _ file }|tee-a $ { log file } then Log '[Error]脚本执行失败。 请确认。' Log '[Error]日志文件: [${logFile}]' exit 1 fi Log '远程执行命令的返回值是: [$sshRet]' Log '[Info]脚本执行成功. 脚本执行成功server IP : $ { server IP } ' log ' [ info ] ssh user : $ { ssh user } ' log ' [ info ] ssh pass 3360 $ { ssh pass

能学一点是一点,至少不是0!

超重!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。