求助 shell 自动交互

sh/bash/dash/ksh/zsh等Shell脚本
回复
knityster
帖子: 6
注册时间: 2009-08-24 23:06

求助 shell 自动交互

#1

帖子 knityster » 2009-09-04 20:04

需求来源: 希望 vncviewer 能够记住密码自动登录

场景:
执行如下指令:
# vncviewer -passwdInput=true name=192.168.2.93 192.168.2.93:1
TigerVNC Viewer for X version 0.0.91 - built Aug 14 2009 09:53:29
Copyright (C) 2002-2005 RealVNC Ltd.
Copyright (C) 2000-2006 TightVNC Group
Copyright (C) 2004-2009 Peter Astrand for Cendio AB
See http://www.tigervnc.org for information on TigerVNC.

Fri Sep 4 20:04:24 2009
CConn: connected to host 192.168.2.93 port 5901
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8

出现上述信息后,我再直接输入服务器的密码将可以连接上去了。

我的问题:
有什么办法可以自动输入预先定义的密码,以实现自动登录呢?
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 求助 shell 自动交互

#2

帖子 eexpress » 2009-09-04 20:52

expect
● 鸣学
头像
ciciluter
帖子: 50
注册时间: 2009-08-19 21:51

Re: 求助 shell 自动交互

#3

帖子 ciciluter » 2009-09-04 20:55

最简单的,比如,你要执行fdisk -l ,需要sudo,然后输入用户密码,可以这么写:

代码: 全选

#/bin/sh
echo 密码 | sudo fdisk -l
希望对你有帮助
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: 求助 shell 自动交互

#4

帖子 aerofox » 2009-09-06 7:22

ciciluter 写了:最简单的,比如,你要执行fdisk -l ,需要sudo,然后输入用户密码,可以这么写:

代码: 全选

#/bin/sh
echo 密码 | sudo fdisk -l
希望对你有帮助
这个方法真是简单,可惜不管用的。

vncviewer 是可以用使用一个文件作身份论证的,这样就不用输入密码了。具体过程我忘了,因我家里的机器用不上 vnc,不想再安上 vnc 来试一下。等我上班后看看当时我是怎么做的,如果那时楼主还没找到办法,我再贴出来。
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: 求助 shell 自动交互

#5

帖子 tusooa » 2009-10-05 16:28

代码: 全选

echo <password> | vncviewer -passwdInput=true name=192.168.2.93 192.168.2.93:1

代码: 全选

] ls -ld //
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: 求助 shell 自动交互

#6

帖子 aerofox » 2009-10-05 19:39

tusooa 写了:

代码: 全选

echo <password> | vncviewer -passwdInput=true name=192.168.2.93 192.168.2.93:1
这样至少有个风险:有人从进程参数中发现你的密码。
可以用 vncpasswd 生成一个 passwd 文件,然后用 -passwd (或 -PasswordFile)参数传给 vncviewer。
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: 求助 shell 自动交互

#7

帖子 tusooa » 2010-01-26 22:16

ls,

代码: 全选

>> type echo
echo 是一个 shell 内部命令

代码: 全选

] ls -ld //
回复