Created
July 3, 2024 17:50
-
-
Save ShadSterling/a205e0037b33892fe15ca3e85df37b3d to your computer and use it in GitHub Desktop.
~/bin/screento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
dest="$1" | |
shift | |
name="$1" | |
shift | |
autoname=false | |
if [ "" == "$name" ]; then | |
name=`random-string 10` ## see https://gist.github.com/ShadSterling/95ca749b625916529af12af9537a8ee2 | |
autoname=true | |
fi | |
if [ "" == "$dest" ]; then | |
echo "usage: $0 <[user@]host> [session_name] [remote_command]" | |
echo "if session_name is not given a random name like $name will be chosen" | |
else | |
cmd="ssh -t \"$dest\" screen -aAdRUS \"$name\" \"$@\"" | |
echo $cmd | |
#$cmd | |
ssh -t "$dest" screen -aAdRUS "$name" "$@" | |
exit=$? | |
if [ "255" == "$exit" ]; then | |
echo "Connection Lost!" | |
if [ "true" == "$autoname" ]; then | |
echo "recover with session name: $name" | |
echo "screento \"$dest\" \"$name\"" | |
fi | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment