Skip to content

Instantly share code, notes, and snippets.

@ericblue
Last active November 19, 2016 20:04
Show Gist options
  • Save ericblue/5bad210e113c56ade8766506fc99e611 to your computer and use it in GitHub Desktop.
Save ericblue/5bad210e113c56ade8766506fc99e611 to your computer and use it in GitHub Desktop.
#!/bin/bash
# launch_screens.sh - https://gist.github.com/ericblue/5bad210e113c56ade8766506fc99e611
# Launch script using screens to automatically create named sessions and launch executed commands while detaching immediately
# Useful as a startup helper script to create multiple screen sessions you can later reattach to (e.g. screen -r screen1)
# Key name = the screen session name
# Key value = command to execute
declare -A screens=(
["screen1"]="/usr/bin/top"
["screen2"]="/bin/ls"
)
# For Ubuntu on startup
chmod 777 /var/run/screen
for s in "${!screens[@]}"; do
echo "killing existing screen $s"
screen -S $s -X quit
echo "Launching screen $s with command ${screens[$s]}"
# bash -c and the follow-up 'exec bash' is used to keep the screen session persistent upon detach
screen -dmS $s bash -c "${screens[$s]}; exec bash"
echo
done
echo "Current screens..."
sleep 1 && screen -ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment