Difference between revisions of "Linux: screen command"
Jump to navigation
Jump to search
| Line 17: | Line 17: | ||
* <code>stuff</code> = stuff command lets you send keystrokes | * <code>stuff</code> = stuff command lets you send keystrokes | ||
* <code>$</code> = <code>$</code> before the command is to make the shell parse the <code>\n</code> inside the quotes and the newline is required to execute the command (like when you press enter) | * <code>$</code> = <code>$</code> before the command is to make the shell parse the <code>\n</code> inside the quotes and the newline is required to execute the command (like when you press enter) | ||
| − | * <code>'cd /tmp\n'</code> = the command to run followed by <code>/n</code> | + | * <code>'cd /tmp\n'</code> = the command to run followed by <code>\n</code> keystroke |
| + | |||
| + | == Injecting a command into an existing, remote screen session == | ||
| + | Much the same as above: | ||
| + | <syntaxhighlight> | ||
| + | ssh 172.28.130.1 screen -dmS test | ||
| + | ssh 172.28.130.1 screen -S test -p 0 -X stuff "/pool/LEOPARD150723M_2.16/Yafuflash\ -kcs\ /pool/LEOPARD150723M_2.16/LEOPARD150723M_2.16.ima\ -ignore-module-location"`echo -ne '\015'` | ||
| + | </syntaxhighlight> | ||
| + | * <code>-s test</code> = name of the screen session | ||
| + | * <code>-p 0</code> = selection screen 0 of screen session | ||
| + | * <code>-X</code> = send commands to a running screen session | ||
| + | * <code>stuff</code> = stuff command lets you send keystrokes | ||
| + | * <code>`echo -ne '\015'`</code> = send a carriage return after the main command, similar to <code>$</code> and <code>\n</code> in previous example. | ||
Revision as of 11:40, 30 July 2015
Initiate a screen session and disconnect immediately
[root@nodea ~]# screen -S 'jhtest' -d -m
[root@nodea ~]# screen -list
There is a screen on:
2653.jhtest (Detached)Parse a command to a running screen session
- Initiate and disconnect from your named screen session
screen -r "jhtest" -X stuff $'cd /benchmark\n'-r= reconnect screen session"jhtest"= name of the screen session-X= send commands to a running screen sessionstuff= stuff command lets you send keystrokes$=$before the command is to make the shell parse the\ninside the quotes and the newline is required to execute the command (like when you press enter)'cd /tmp\n'= the command to run followed by\nkeystroke
Injecting a command into an existing, remote screen session
Much the same as above:
ssh 172.28.130.1 screen -dmS test
ssh 172.28.130.1 screen -S test -p 0 -X stuff "/pool/LEOPARD150723M_2.16/Yafuflash\ -kcs\ /pool/LEOPARD150723M_2.16/LEOPARD150723M_2.16.ima\ -ignore-module-location"`echo -ne '\015'`-s test= name of the screen session-p 0= selection screen 0 of screen session-X= send commands to a running screen sessionstuff= stuff command lets you send keystrokes`echo -ne '\015'`= send a carriage return after the main command, similar to$and\nin previous example.