diff --git a/files/image_config/bash/bash.bashrc b/files/image_config/bash/bash.bashrc index 6651a51ceed0..0f19263ae04a 100644 --- a/files/image_config/bash/bash.bashrc +++ b/files/image_config/bash/bash.bashrc @@ -56,3 +56,20 @@ fi # Automatically log out console ttyS* sessions after 15 minutes of inactivity tty | grep ttyS >/dev/null && TMOUT=900 + +# if SSH_TARGET_CONSOLE_LINE was set, attach to console line interactive cli directly +if [ -n "$SSH_TARGET_CONSOLE_LINE" ]; then + if [ $SSH_TARGET_CONSOLE_LINE -eq $SSH_TARGET_CONSOLE_LINE 2>/dev/null ]; then + # enter the interactive cli + connect line $SSH_TARGET_CONSOLE_LINE + + # test exit code, 1 means the console switch feature not enabled + if [ $? -ne 1 ]; then + # exit after console session ended + exit + fi + else + # exit directly when target console line variable is invalid + exit + fi +fi