Non sono esattamente sicuro di ciò che vuoi che accada: vuoi uno script che crei la sessione dello schermo con due finestre per due comandi o vuoi eseguire uno script in una finestra dello schermo che esegue un comando, quindi crea un nuovo finestra per la seconda?
Il secondo è facile, quindi cominciamo con quello:
#!/bin/bash
command1
screen command2
L'esecuzione di "schermo" all'interno dello schermo creerà una nuova finestra nella sessione corrente, non ne aprirà una nuova. Ma tornerà immediatamente, quindi dopo l'ultima riga lì, lo script uscirà mentre command2 è ancora in esecuzione. E quando command2 è terminato, la sua finestra si chiuderà.
La prima interpretazione della tua domanda è un po 'più difficile, quindi andiamo avanti e risolviamo quanto sopra mentre ci siamo:
#!/bin/bash
# Need to positively identify the session name:
SESSION=mysession.$$
echo "TO ATTACH TO SESSION: screen -r ${SESSION}"
# For signalling and stuff
FLAGDIR=$(mktemp -d)
# To keep the windows around after the commands are done,
# set the "zombie" option (see the man-page)
echo "source $HOME/.screenrc" > ${FLAGDIR}/screenrc
echo "zombie xy" >> ${FLAGDIR}/screenrc
# Use that temporary screenrc; create a detached session:
screen \
-c ${FLAGDIR}/screenrc \
-d -m \
-S ${SESSION} \
bash -c "command1 ; touch ${FLAGDIR}/done"
# Wait for command1 to terminate
while [[ ! -f ${FLAGDIR}/done ]] ; do sleep 1 ; done
# Now start command2 in a new window, by sending a remote command:
screen -S $SESSION -X screen command2
# Don't need this any more:
rm -rf ${FLAGDIR}
Lo script verrà avviato command1, attendi il completamento, quindi avvia command2e termina. Come se dovessi correre command1 ; command2 &, ma con l'output altrove. Sono sicuro che puoi capire come eseguire command1in background.