首页 | 我和企鹅 | 软件相关 | 乱七八糟 | 相册 | 留言 | 登陆 | 注册
3上一篇 [转贴]一个北大才子的失恋感悟下一篇 [转贴]当他不爱你的时候4
中文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链接
字体:
评论(0) | 引用(0) | 阅读10次

 
提示:  
此文还没有评论。
称呼:    登陆   注册
    不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
提交时自动将内容复制到剪贴板

 
快考试了,好好复习,少上网!
点击查看我的个人信息
xiaosuo
日志: 24
评论: 7
到访: 579 [统计]
今日: 2
用户: 3 [列表]
在线: 1
342006 - 0534
 123456
78910111213
14151617181920
21222324252627
28293031   
最新日志
· 无题 (2005-4-30)
· 疲惫的两天 (2005-4-17)
· 修正d4x的中文显示 (2004-12-31)
· 圣诞节 (2004-12-25)
· glc系列脚本 (2004-12-23)
· 生日 (2004-12-9)
· 联谊宿舍来看我们。 (2004-12-5)
· 无题 (2004-12-4)
· 沉痛悼念陈省身先生! (2004-12-3)
· [转贴]一个北大才子的失... (2004-12-2)
最新评论
· ft,昨天到注意到dow... (2005-1-3)
· 谢谢夸奖,我会继续努力的... (2004-12-23)
· 超好啊!在FC3安装,执... (2004-12-23)
· 当然是转贴了。<b... (2004-11-12)
· 是你自己写的吗?有点长,... (2004-11-12)
· 歌词路径就是你存放lrc... (2004-11-7)
· 请问怎样配置歌词路径和歌... (2004-11-7)
· 模板是不错的,就是很多人... (2004-10-25)
· 呵呵,不错的模板,稍微修... (2004-10-25)

搜索
高级
归档
友情链接
杂项
Get RSS Feed (Version 1.0) Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3) 编码:  UTF-8
Creative Commons Powered by Bo-Blog V1.7.0108.2

 
5 reads, 2 writes, processed in 0.2033400s, Gzip enabled