2009-06-12 74 views
5

我確定手冊中有一個答案可以屏幕顯示,但我找不到它! 我希望由GNU屏幕產生的bash shell除了已經運行的.bashrc文件之外還有源文件。運行bash初始化腳本的GNU屏幕

我無法在.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。

+0

如果自定義的init腳本恰好是`.bash_profile`(如在我的情況),然後screen_bash.sh`的'內容爲更好:`慶典--login` – janos 2012-07-08 08:50:49

回答

4

您是否希望每次打開新的屏幕窗口時都會收到此文件?如果是這樣,shell命令允許您覆蓋創建新的屏幕窗口時運行的內容(默認情況下它只是$ SHELL)。您可以將其設置爲最終運行shell的腳本。

+0

謝謝 - 這和其他答案整理出來。 – 2009-06-12 09:12:41

2
screen bash --rcfile yourfile.rc 

yourfile.rc應該來源.bashrc

編輯:這並沒有真正做你想做的,我才意識到你可能希望它適用於所有通過屏幕開始。

+0

謝謝 - 我把你的建議在我的.screenrc使用shell命令(如上所述),它的工作。 – 2009-06-12 09:13:17

0

我以前一直在做,但現在我意識到最好是作爲系統init服務運行。你可以找到我的腳本附加到this bug report。希望它可以作爲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 
}