shell远程上传代码

shlvshe00 2014-08-30 09:36:49
我想在服务器A上将脚本test.sh的内容上传到服务器B上,以下是我的代码
test.sh //要上传的脚本
#!/bin/bash
function log_echo()
{
mkdir 2290
chmod 777 2290
cd 2290
touch ttt
chmod 777 ttt
}

function log_cat()
{
code=$(cat<&0)
echo $code
ret=$?
echo $ret
}
cmd=$1
shift
$cmd "$@"


remote.sh //执行上传动作的脚本
#!/bin/bash

cmd=$(cat<&0)
cmd1=$(cat<<REMOTE
$cmd
REMOTE)

ssh agishl@1.1.1.1<<EOF_END
echo "$cmd1">>test.sh
./test.sh log_echo
EOF_END
echo 1


两台机器间已配置了信任关系,执行remote.sh脚本后会报错
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
/bin/bash: Event not found.
如果我把test.sh脚本中#!/bin/bash改成#\!/bin/bash,又会报
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
Unmatched ".
求大神帮忙
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 3 楼 shlvshe00 的回复:
[quote=引用 2 楼 micropentium6 的回复:] there is a command called "scp"...
scp是直接传送文件吧,我想先获取脚本内容,然后把内容上传到B服务器, 其实是想在远端机器上执行脚本中的函数,但是不能直接上传脚本啊[/quote] allright, I will not ask why you want to do this shady thing:) you don't have to upload ur script over ssh agishl@1.1.1.1 'bash -s' < test.sh
shlvshe00 2014-08-30
  • 打赏
  • 举报
回复
引用 2 楼 micropentium6 的回复:
there is a command called "scp"...
scp是直接传送文件吧,我想先获取脚本内容,然后把内容上传到B服务器, 其实是想在远端机器上执行脚本中的函数,但是不能直接上传脚本啊
  • 打赏
  • 举报
回复
there is a command called "scp"...
shlvshe00 2014-08-30
  • 打赏
  • 举报
回复
在线等,大神在哪里

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧