脚本源码:
[php]
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 {
"assword:" { 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]
[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 "lease 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 "lease 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!"
[/php]
前些天在用这个代码提交更改的时候,因为cvs -m "some reason" somefile中引号的问题,使得脚本不能正常工作,所以改写了代码现在应该没有什么问题了。
[php]
xiaosuo@center cvs $ cat autocvs
#!/usr/bin/expect -f
###
###it is so magic!~_~
###
set timeout 300
set args ""
set lastarg ""
for {set i 0} {$i < $argc} {incr i} {
if {[string compare $lastarg "-m"] == 0} {
set args "$args \{\"[lindex $argv $i]\"\}"
} else {
set args "$args [lindex $argv $i]"
}
set lastarg [lindex $argv $i]
}
eval spawn /usr/bin/cvs $args
expect {
"assword:" { send "$env(PassWord)\r" }
timeout { puts "Timeout while connecting to the server"; exit }
default { puts "Some thing error while executing"; exit }
}
expect {
"assword:" { puts "\nPlease check your password. run cvs login"; exit}
timeout { puts "Timeout while waiting for the answer"; exit }
default { exit }
}
[/php]
[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
unset PassWord
stty -echo
echo -n "lease input you password for GLC CVS:"
read PassWord
while [ X$PassWord = X ]
do
echo
echo -n "lease input you password for GLC CVS:"
read PassWord
done
export PassWord
stty echo
echo
elif [ X$1 = Xlogout ] ; then
export CVSRSH=${CVSRSHBAK}
export CVSROOT=${CVSROOTBAK}
unset CVSRSHBAK
unset CVSROOTBAK
unset PassWord
unset cvs
unset GLCCVS
echo "Thanks for use this script!"
elif [ X$PassWord = X ] ; then
echo "lease Login with the command \"cvs login\"!"
elif [ $# -ne 0 ] ; then
args=$#
n=0
argv=""
while [ $n -lt $args ]
do
argv="$argv \"$1\""
shift
n=$(($n+1))
done
eval autocvs $argv
fi
}
if [ X${GLCCVS} = X ]
then
export GLCCVS=init
export CVSRSHBAK=${CVSRSH}
export CVSROOTBAK=${CVSROOT}
export CVSRSH=ssh
export CVSROOT=:ext:glc@www.magiclinux.org:/sfroot/home/groups/glc/cvsroot
fi
unset PassWord