u
This commit is contained in:
6
myip.sh
6
myip.sh
@@ -1,4 +1,8 @@
|
|||||||
echo Local IP: $(echo `hostname -I` | awk '{print $1;}')
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
echo Local IP: $(ifconfig en0 | grep "inet " | awk '{print $2}')
|
||||||
|
else
|
||||||
|
echo Local IP: $(echo `hostname -I` | awk '{print $1;}')
|
||||||
|
fi
|
||||||
|
|
||||||
echo Public IP: `curl -s ifconfig.me`
|
echo Public IP: `curl -s ifconfig.me`
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -124,12 +124,27 @@ esac
|
|||||||
# - `7`: White
|
# - `7`: White
|
||||||
# others:
|
# others:
|
||||||
# \w shows absolute path, \W shows current folder.
|
# \w shows absolute path, \W shows current folder.
|
||||||
if [ "$(whoami)" = "root" ]; then
|
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
MYIPLAN=$(ifconfig en0 | grep "inet " | awk '{print $2}')
|
||||||
|
else
|
||||||
|
MYIPLAN=$(echo `hostname -I` | awk '{print $1;}')
|
||||||
|
fi
|
||||||
|
MYIPPUB=$(curl -s ifconfig.me)
|
||||||
|
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
PSTYLE=04
|
||||||
|
PTYPE=3
|
||||||
|
elif [ "$(whoami)" = "root" ]; then
|
||||||
PSTYLE=07
|
PSTYLE=07
|
||||||
PTYPE=4
|
PTYPE=4
|
||||||
|
AS_ROOT="#"
|
||||||
else
|
else
|
||||||
PSTYLE=07
|
PSTYLE=07
|
||||||
PTYPE=3
|
PTYPE=3
|
||||||
|
if [[ -n "$SSH_CONNECTION" ]]; then
|
||||||
|
IN_SSH="$"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$(uname)" = "Darwin" ]; then
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
MYOSVERSION=Mac`sw_vers -productVersion`
|
MYOSVERSION=Mac`sw_vers -productVersion`
|
||||||
@@ -140,13 +155,10 @@ elif [ -f /etc/debian_version ]; then
|
|||||||
elif [ -f /etc/ubuntu_version ]; then
|
elif [ -f /etc/ubuntu_version ]; then
|
||||||
MYOSVERSION=Ubt`cat /etc/ubuntu_version 2>/dev/null`
|
MYOSVERSION=Ubt`cat /etc/ubuntu_version 2>/dev/null`
|
||||||
fi
|
fi
|
||||||
if [[ -n "$SSH_CONNECTION" ]] || [[ "$(uname)" != "Darwin" ]]; then
|
|
||||||
IN_SSH="ssh$"
|
|
||||||
fi
|
|
||||||
if [ "$color_prompt" = yes ]; then
|
if [ "$color_prompt" = yes ]; then
|
||||||
PS1='<\[\033[$PSTYLE;${PTYPE}2m\]\t\[\033[00m\]#\[\033[$PSTYLE;${PTYPE}5m\]\u\[\033[00m\]@\[\033[$PSTYLE;${PTYPE}1m\]\h\[\033[00m\]=\[\033[$PSTYLE;${PTYPE}4m\]$(uname -m),$(uname),$MYOSVERSION\[\033[00m\]:\[\033[$PSTYLE;${PTYPE}2m\]\w\[\033[00m\]>\[\033[$PSTYLE;${PTYPE}7m\]$IN_SSH\[\033[00m\] '
|
PS1='<\[\033[$PSTYLE;${PTYPE}2m\]\t\[\033[00m\]#\[\033[$PSTYLE;${PTYPE}5m\]\u\[\033[00m\]@\[\033[$PSTYLE;${PTYPE}1m\]\h\[\033[00m\]=\[\033[$PSTYLE;${PTYPE}1m\]$MYIPPUB\[\033[00m\]~\[\033[$PSTYLE;${PTYPE}4m\]$(uname -m),$(uname),$MYOSVERSION\[\033[00m\]:\[\033[$PSTYLE;${PTYPE}2m\]\w\[\033[00m\]>\[\033[$PSTYLE;${PTYPE}7m\]$IN_SSH$AS_ROOT\[\033[00m\] '
|
||||||
else
|
else
|
||||||
PS1='<\t#\u@\h=$(uname -m),$(uname),$MYOSVERSION:\w>$IN_SSH ' # \w shows absolute path, \W shows current folder.
|
PS1='<\t#\u@\h=$MYIPPUB~$(uname -m),$(uname),$MYOSVERSION:\w>$IN_SSH$AS_ROOT ' # \w shows absolute path, \W shows current folder.
|
||||||
fi
|
fi
|
||||||
unset color_prompt force_color_prompt
|
unset color_prompt force_color_prompt
|
||||||
|
|
||||||
|
|||||||
20
ssh.sh
20
ssh.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "Usage: $(basename $0) [selected_index] [to_run_cmd]"
|
echo "Usage: $(basename $0) [host_to_ssh] [cmd_to_run]"
|
||||||
|
|
||||||
# Ensure jq is installed
|
# Ensure jq is installed
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &> /dev/null; then
|
||||||
@@ -38,7 +38,7 @@ done
|
|||||||
# Check if a command-line argument is provided
|
# Check if a command-line argument is provided
|
||||||
if [ "$1" != "" ]; then
|
if [ "$1" != "" ]; then
|
||||||
# 如果提供了参数,则直接使用这个前缀
|
# 如果提供了参数,则直接使用这个前缀
|
||||||
user_input=$1
|
host_to_ssh=$1
|
||||||
else
|
else
|
||||||
echo "Select a target to connect via SSH, or press 0 to exit:"
|
echo "Select a target to connect via SSH, or press 0 to exit:"
|
||||||
echo
|
echo
|
||||||
@@ -49,7 +49,7 @@ else
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo
|
echo
|
||||||
read -p "请输入要连接的主机前缀: " user_input
|
read -p "请输入要连接的主机前缀: " host_to_ssh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@@ -57,7 +57,7 @@ echo
|
|||||||
# 查找用户输入对应的索引
|
# 查找用户输入对应的索引
|
||||||
selected_index=-1
|
selected_index=-1
|
||||||
for i in "${!prefixes[@]}"; do
|
for i in "${!prefixes[@]}"; do
|
||||||
if [[ "${prefixes[$i]}" == "$user_input" ]]; then
|
if [[ "${prefixes[$i]}" == "$host_to_ssh" ]]; then
|
||||||
selected_index=$i
|
selected_index=$i
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@@ -84,13 +84,13 @@ fi
|
|||||||
echo "::*** Connecting to ${label}"
|
echo "::*** Connecting to ${label}"
|
||||||
if [ "$password" != "null" ]; then
|
if [ "$password" != "null" ]; then
|
||||||
if command -v sshpass &> /dev/null; then
|
if command -v sshpass &> /dev/null; then
|
||||||
echo "::*** sshpass -p $password -Y -p $port $username@$host"
|
echo "::*** sshpass -p $password -Y -p $port $username@$host '$2'"
|
||||||
sshpass -p "$password" ssh -Y -p "$port" "$username@$host" $2
|
sshpass -p "$password" ssh -Y -p "$port" "$username@$host" "$2"
|
||||||
else
|
else
|
||||||
echo "::*** ssh -Y -p $port $username@$host"
|
echo "::*** ssh -Y -p $port $username@$host '$2'"
|
||||||
ssh -Y -p "$port" "$username@$host" $2
|
ssh -Y -p "$port" "$username@$host" "$2"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "::*** ssh -Y -p $port $username@$host"
|
echo "::*** ssh -Y -p $port $username@$host '$2'"
|
||||||
ssh -Y -p "$port" "$username@$host" $2
|
ssh -Y -p "$port" "$username@$host" "$2"
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user