Last active
November 19, 2016 20:04
-
-
Save ericblue/5bad210e113c56ade8766506fc99e611 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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