Chinaunix
标题:
怎么用shell ssh,然后再exit?
[打印本页]
作者:
xiaobaibbb
时间:
2009-02-10 00:12
标题:
怎么用shell ssh,然后再exit?
假设已经用ssh-keygen生成密钥,可以不用输入密码直接 ssh ip
作者:
皇家救星
时间:
2009-02-10 00:27
ip="10.10.110.1"
ssh $ip << EOF
ls
EOF
作者:
xiaobaibbb
时间:
2009-02-10 00:31
!/bin/sh
ip=192.168.0.7
ssh $ip << EOF
ls -ahl >> /root/ls.txt
exit
EOF
root@debian:~# sh scp_mv.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
stdin: is not a tty
作者:
xiaobaibbb
时间:
2009-02-10 00:32
#!/bin/sh
ip="192.168.0.7"
ssh $ip && ls -ahl >> /root/ls.txt && exit
EOF
这样就直接登陆到目标机器,然后命令就结束了。。
作者:
xiaobaibbb
时间:
2009-02-10 00:39
#!/bin/sh
ip="192.168.0.7"
ssh -tt $ip << EOF
ls -ahl >> /root/ls.txt && exit
EOF
thx a million 皇家救星 ~
作者:
xiaobaibbb
时间:
2009-02-10 01:46
#!/bin/sh
cd /root/
tar zcvf /root/etc.tar.gz /etc/
ip="192.168.0.7"
scp etc.tar.gz $ip:/root/test/
ssh -tt $ip << EOF
cd /root/test/
tar zxvf etc.tar.gz /root/123
exit
EOF
postfix:~/test# tar zxf etc.tar.gz /root/123
tar: /root/123: Not found in archive
tar: Error exit delayed from previous errors
怎么一回事?
作者:
waker
时间:
2009-02-10 08:05
tar zxvf etc.tar.gz -C /root/123
或
( cd /root/123; tar zxvf etc.tar.gz )
猜猜猜
作者:
xiaobaibbb
时间:
2009-02-10 12:25
感谢楼上的老大解答~
还有个问题,如果ssh到其他机器,如何echo信息到本机?
作者:
yingweixu
时间:
2009-02-10 13:07
ssh到别的机器,还要把显示的信息弄到本地,估计只有先把显示的信息保存,然后在传回来了!
echo 1 > ./moniter.txt
但是这里要传回的话就需要密码了,因为他的信任关系是单向的!
作者:
jxg945
时间:
2009-02-10 14:09
直接执行 ssh XXX.XXX.XXX.XXX "echo $PATH" , 显示的是远程机器的$PATH
作者:
xiaobaibbb
时间:
2009-02-10 21:35
受教了。。。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2