中文portage自动输入密码脚本
by xiaosuo | 软件相关 |
2004年12月1日12:28星期三 |
由于glc的cvs系统用ext方式,使得我们无法像pserver那样用cvs login一次性登录,给我们的维护工作带来了不便,虽然说这样更安全。所以我写个这两个脚本。 是用方法: 1.将这两个脚本拷贝到你的cvs目录下面。 2.修改脚本glc_cvs的script_dir变量为你存放这两个脚本的目录。 3.
代码 | $source glc_cvs $cvs login
|
输入密码 和正常的cvs一样操作
提示:为了安全起见在你离开电脑后,输入cvs logout 退出!!! 依赖性:需要安装expect!
代码 | xiaosuo@center cvs $ cat autocvs #!/usr/bin/expect -f ### ###the args[0]=PassWord args[1]... is the CVS arguments ### set timeout 300 set args [lindex $argv 1] spawn $env(script_dir)/glc_cvs true $args expect { "Password:" { send "[lindex $argv 0]\r" } timeout { puts "Timeout while connect to the server\n"; exit } } expect timeout { puts "Timeout while wait for the answer\n"; exit }
PHP源码: xiaosuo@center cvs $ cat glc_cvs #!/bin/bash ### ###Set the environment of the GLC CVS and the AUTOMTIC COMMANDS ###If you think this is not security enough you can't use this script ~_~ ###But I encourage you to use it because it is HELPFUL ### #redefine the cvs command function cvs() { if [ X$1 = Xlogin ] ; then stty -echo while [ X$PassWord = X ] do echo -n "Please input you password for GLC CVS:" read PassWord done stty echo elif [ X$1 = Xlogout ] ; then unset PassWord unset script_dir echo "Thanks for use this script" exit elif [ X$PassWord = X ] ; then echo "Please Login with the command \"cvs login\"!" elif [ X$1 = Xtrue ] ; then shift echo $@ /usr/bin/cvs $@ exit elif [ $# -ne 0 ] ; then $script_dir/autocvs $PassWord "$*" fi }
#the autocvs recall this script, so add this line cvs $@
#set the CVS variables export CVSRSH=ssh export CVSROOT=:ext:glc@www.magiclinux.org:/sfroot/home/groups/glc/cvsroot
#set the scripts variables unset PassWord unset script_dir script_dir="/home/xiaosuo/work/cvs"
export PassWord export script_dir echo "Setup the Environment successfully!"
|
后记:写这个脚本着实费了我很长时间,先是以前文档中的index在新的tcl中不能用改用lindex,所以不得不详细的看tcl的教程,后来就是autocvs那个文件中调用spawn的那行,死活cvs就是说那是个错误命令,后来详细推敲才知道原来spawn用的是exec调用,而这个调用参数个数是预定的,很有可能直接和main的argc和argv打交道,所以cvs将这些东西看成是一个参数当然就会报错了,又想到用system,可是不知道怎们设定expect这个进程,最后不得已有了这个比较折衷而且笨拙的办法重新调用glc_cvs。 linuxsir链接 |
字体:大 中 小 |
|
|
|
|
|