5

我确定在屏幕手册中有对此的答案,但我找不到它!除了已经运行的 .bashrc 之外,我还希望 GNU screen 生成的 bash shell 在文件中提供源代码。

我无法调用 .bashrc 中的文件,因为在我们的网站上,.bashrc 文件会在登录时自动重新生成。

有任何想法吗?

编辑:

我创建了这个小脚本(screen_bash.sh):

bash --rcfile ~/.screen_bashrc

然后添加

shell $HOME/screen_bash.sh

到我的 .screenrc

~/.screen_bashrc 文件是

<my_setup_stuff>
export SHELL=bash

SHELL=bash 是必要的,这样 vim 之类的程序才能正确启动子 shell。

4

3 回答 3

4

您是否希望每次打开新的屏幕窗口时都获取此文件?如果是这样,shell命令允许您覆盖在创建新屏幕窗口时运行的内容(默认情况下它只是 $SHELL)。您可以将其设置为您选择的脚本,最后运行您的 shell。

于 2009-06-12T08:28:59.480 回答
2
screen bash --rcfile yourfile.rc

yourfile.rc应源.bashrc

编辑:这并没有真正做到你想要的,我刚刚意识到你可能希望它适用于所有由屏幕启动的 shell。

于 2009-06-12T08:28:31.730 回答
0

我以前一直这样做,但现在我意识到最好作为系统初始化服务运行。您可以在此错误报告中找到我的脚本。希望它可以作为 Gentoo 中屏幕 ebuild 的一部分提供。我会在github上保持更新。

start() {

for SCREENRC in /etc/screen.d/* ; do 

    SESSION="$(basename $SCREENRC)"

    ## I don't think there may be a security issue,
    ## provided that users will not be have write
    ## permission in /etc/screen.d/ and if anyone
    ## gained access to mod the session file, they
    ## are in already anyhow!
    BELONGS="$(stat $SCREENRC --printf=%U)"

    MYSHELL="$(getent passwd $BELONGS | cut -d: -f7)"


    COMMAND="/usr/bin/screen -- -U -D -m -c ${SCREENRC} -S ${SESSION} -t ${SESSION}"

    ## Why on earth would one write this ???
    #HOMEDIR="$(getent passwd $BELONGS | cut -d: -f6)"

    ebegin "Starting screen session ${SESSION} for ${BELONGS}"

    PIDFILE="/var/run/screen.${BELONGS}.${SESSION}.pid"

    start-stop-daemon \
        --env TERM="rxvt" \
        --env HOME="~${BELONGS}" \
        --env SCREEN_SESSION=${SESSION} \
        --user $BELONGS \
        --chdir "~${BELONGS}" \
        --make-pidfile \
        --background \
        --pidfile=${PIDFILE} \
        --exec ${COMMAND}
    eend $?
done

}




stop() {

## Perhaps we should determin this by pidfiles ...
## but this way is not bad either!
for SCREENRC in /etc/screen.d/* ; do 

    SESSION="$(basename $SCREENRC)"
    BELONGS="$(stat $SCREENRC --printf=%U)"

    PIDFILE="/var/run/screen.${BELONGS}.${SESSION}.pid"
    PROCESS="$(cat ${PIDFILE})"

    if [ -e /proc/${PROCESS}/status ]; then

    grep -i "Name:" /proc/${PROCESS}/status | grep -iq "screen" || continue

    ebegin "Stopping screen session ${SESSION} for ${BELONGS} (PID: ${PROCESS})"

    ## There other things we can try here ...
    ## perhaps add /etc/screen.d/$SESSION.stop

    ## It will CERTAINly kill the righ screen!
    CERTAIN="${PROCESS}.${SESSION}"
    env TERM="urxvt" \
        start-stop-daemon \
            --user ${BELONGS} \
            --exec /usr/bin/screen -- -S $CERTAIN -X quit
    eend $?

    fi

    rm -f $PIDFILE

done
}
于 2011-09-01T16:39:52.310 回答