Skip to content

Instantly share code, notes, and snippets.

@ShadSterling
Created July 3, 2024 17:50
Show Gist options
  • Save ShadSterling/a205e0037b33892fe15ca3e85df37b3d to your computer and use it in GitHub Desktop.
Save ShadSterling/a205e0037b33892fe15ca3e85df37b3d to your computer and use it in GitHub Desktop.
~/bin/screento
#!/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