Create screen with a bash script and send commands to it.

Source: Internet
Author: User
Tags sessions
What is screen.

GNU Screen is a free software developed by the GNU Program for command-line terminal switching. This software allows users to simultaneously connect multiple local or remote command sessions and switch between them freely.

GNU screen can be viewed as a command-line interface version of the window manager. It provides a unified interface for managing multiple sessions and corresponding functionality.


Why do you create screen with scripts?

In order to take advantage of the server's multiple CPUs, we often need to create multiple screens at the same time, if the number of screen is very many, manual creation can be very cumbersome.


How to create screen with a bash script and send commands to it.

If we write Screen-s My_screen directly in the script, it will cause the script to not continue. For the script to proceed, the specific code to create screen is as follows:

screen_name=$ "My_screen"
Screen-dms $screen _name
Now, we have created a window named My_screen. Then, we need to send a specific command to it. We use the following command:

cmd=$ "Java Test";
Screen-x-S $screen _name-p 0-x stuff "$cmd"
screen-x-S $screen _name-p 0-x stuff $ ' \ n '
So we sent a Java Test command to screen.

If you want to exit the window, you can then send an exit command to note

The command sent in this way cannot be too long, or it will cause the script to get stuck.

If you need to send a long command, or send a number of consecutive commands, it is best to write a separate script, send a script command to screen, and let screen execute the new script.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.