From c3d5cdbb54304850a2d85fb7ef592ea31aee364f Mon Sep 17 00:00:00 2001 From: Blueve <672454911@qq.com> Date: Wed, 23 Sep 2020 05:12:44 +0000 Subject: [PATCH 1/3] [bash.bashrc] Add reverse SSH script to bash.bashrc --- files/image_config/bash/bash.bashrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/files/image_config/bash/bash.bashrc b/files/image_config/bash/bash.bashrc index 6651a51ceed0..3d815caf21de 100644 --- a/files/image_config/bash/bash.bashrc +++ b/files/image_config/bash/bash.bashrc @@ -56,3 +56,12 @@ 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 [ ! -z "$SSH_TARGET_CONSOLE_LINE" ]; then + # enter the interactive cli + sudo connect $SSH_TARGET_CONSOLE_LINE + + # exit after console session ended + exit +fi \ No newline at end of file From 060d2aad44a6afbb6abb82c5cba063a344253694 Mon Sep 17 00:00:00 2001 From: Blueve <672454911@qq.com> Date: Sat, 24 Oct 2020 02:38:31 +0000 Subject: [PATCH 2/3] Fix command issue and add emptt line before EOF --- files/image_config/bash/bash.bashrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/image_config/bash/bash.bashrc b/files/image_config/bash/bash.bashrc index 3d815caf21de..643bab238aaa 100644 --- a/files/image_config/bash/bash.bashrc +++ b/files/image_config/bash/bash.bashrc @@ -58,10 +58,10 @@ fi tty | grep ttyS >/dev/null && TMOUT=900 # if SSH_TARGET_CONSOLE_LINE was set, attach to console line interactive cli directly -if [ ! -z "$SSH_TARGET_CONSOLE_LINE" ]; then +if [ -n "$SSH_TARGET_CONSOLE_LINE" ]; then # enter the interactive cli - sudo connect $SSH_TARGET_CONSOLE_LINE + sudo connect line $SSH_TARGET_CONSOLE_LINE # exit after console session ended exit -fi \ No newline at end of file +fi From 23e3185e032d57ca932b55d12b53c919a5639ec9 Mon Sep 17 00:00:00 2001 From: Blueve <672454911@qq.com> Date: Fri, 20 Nov 2020 02:40:05 +0000 Subject: [PATCH 3/3] Add checks for SSH_TARGET_CONSOLE_LINE --- files/image_config/bash/bash.bashrc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/files/image_config/bash/bash.bashrc b/files/image_config/bash/bash.bashrc index 643bab238aaa..0f19263ae04a 100644 --- a/files/image_config/bash/bash.bashrc +++ b/files/image_config/bash/bash.bashrc @@ -59,9 +59,17 @@ 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 - # enter the interactive cli - sudo connect line $SSH_TARGET_CONSOLE_LINE + if [ $SSH_TARGET_CONSOLE_LINE -eq $SSH_TARGET_CONSOLE_LINE 2>/dev/null ]; then + # enter the interactive cli + connect line $SSH_TARGET_CONSOLE_LINE - # exit after console session ended - exit + # 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