Kill screen session in an expect script

expectgnu-screenunix

I start my screen connection with a spawn command within an expect script:
spawn screen /dev/…

But I don't know how I can kill the screen when the script is finished

Best Answer

When you run screen, use the -S option to give it a unique session name. Then, you can send it commands with the -X option. The quit command will kill the screen, like so:

$ screen -S myscreen -d -m
$ screen -ls
There is a screen on:
        2651.myscreen (09/06/2012 04:56:06 PM)        (Detached)
1 Socket in /var/run/screen/S-username.
$ screen -S myscreen -X quit
$ screen -ls
No Sockets found in /var/run/screen/S-username.