我需要写一个shell脚本为计划使用水银每天运行备份的目录。我有大部分的除了我能想出办法的脚本运行时做自动登录完成的用例。

for REPOSITORY in $@ 
do
    cd $REPOSITORY

    # commit the changes
    hg commit -A -m "Commit changes `date`"

    # push the changes to the remote repository
    if hg push 
    then
        logger hg push success
    else
        logger hg push failure
    fi
done

在发出hg的推命令之后显示登录提示。

有帮助吗?

解决方案

水银允许你把用户名和密码的存储库网址:

hg push http://username:password@hg.myco.com/repo

如果你不想把URL在命令行中,你可以编辑的为本地资源库hgrc 文件,并把在default-push URL的用户名和密码:

default-push = http://username:password@hg.myco.com/repo

这意味着任何hg push将使用在hgrc文件中指定的用户名。

其他提示

我同意,你应该配置备份脚本对于非交互式登录。一种方法是使用SSH密钥和更简单的解决方案是直接包含该密码在URL中。

水银1.3使得它更容易在您的配置文件中的HTTP密码。我现在有一个

[auth]
bb.prefix = https://bitbucket.org/mg/
bb.username = mg
bb.password = pw

在我的配置文件部分。这意味着你能避免存储在多个文件中的密码,只专注于确保一个文件。

其实,我为了避免将密码~/.hgrc使用另一项新功能,因为我可能想显示该文件给他人。相反,我有

%include .hgauth

~/.hgrc~/.hgauth具有上述[auth]部和单独是可读的我

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top