LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-29-2007, 03:50 PM   #1
jingo_man
LQ Newbie
 
Registered: Jul 2004
Distribution: red hat fedora core 1
Posts: 9

Rep: Reputation: 0
scripts with screen


i have started using the "screen" utility to launch processes that i need to dis- and re-connect to.

but i also need to stop and start these screen sessions with crontab (i.e. on a schedule)

this is the command i use to start a rtorrent screen session:
screen -d -m rtorrent

currently, i then use this to end it:
screen -r -X quit

however, the proper way to exit rtorrent is by pressing Control-A (key combo) and then the "q" key.

HOW CAN I SCRIPT THIS??!??!?? i am going insane!
so far, i know i need to use the "-X stuff ...." option, but i do not know how to pass in a control key combo sequence!

i have tried this, unsuccessfully:
screen -r -X stuff ^aq

this is within a bash shell session, so alternatively, if anyone can tell me how to script sending a control key combo, this may help...

please, anyone that can help me... you're my only hope!

regards,

jingo_man
 
Old 07-29-2007, 04:11 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can assign the value of ctrl-A in its octal representation to a shell variable, by means of the echo command and then use it in the command line. From man page of echo:
Quote:
If -e is in effect, the following sequences are recognized:
\0NNN the character whose ASCII code is NNN (octal)
so the command substitution
Code:
$(echo -e '\0001')
where 001 is the octal code for Ctrl-A should give the desired value inside scripts or crontab entries.
 
Old 08-18-2007, 08:20 PM   #3
msing
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
Hey, I've been trying to do this also. Actually I'm just trying to use aliases to do some quick gameserver startup/exiting. I've got remote access to my dedicated server that is running CentOS, and I connect to it from my Windows client using PuTTY.

Currently I have these aliases:

alias bf2s='screen -S bf2screen;'
alias bf2run='cd /home/bf2user/gamecreate/bf2/; /bin/bash ./start.sh +dedicated +lowPriority'
alias bf2show='screen -r bf2screen'

And what I do to start up the server is:

- I type bf2s, which opens the blank screen.
- Inside the screen I type bf2run, which starts the gameserver inside the screen session.
- Then I do a Ctrl-A, Ctrl-D to leave the screen.
- If I ever want to view the status I type bf2show, and do another Ctrl-A, Ctrl-D to leave the screen again.
- To shutdown this gameserver I either have to kill the screen and server processes manually by their PID, or I have to type bf2show, and then type exit, to close the screen session containing the game server.

What I'd like to do is:

- Have an alias (or a script that could be called by an alias) that would start up the server inside a screen using only one command.
- Have an alias (or a script that could be called by an alias) that would shutdown the server and the screen using only one command.

I've tried a number of things including piping and using < and > to send commands to the screen from a single prompt with no luck.

Can anyone give me a clue here? I've taken a basic linux class and am taking an Admin and Install linux class this coming semester, but this is beyond my knowledge.

Many thanks for any help!

- Matt
 
Old 08-19-2007, 06:22 AM   #4
fvu
LQ Newbie
 
Registered: Nov 2006
Distribution: Ubuntu 7.10
Posts: 28

Rep: Reputation: 15
jingo_man:
# Start screen session `rtorrent'
screen -S RTORRENT -d -m rtorrent
# Stop screen session `rtorrent'
screen -S RTORRENT -p 0 -X stuff ^Aq # Enter literal `^A' in bash by pressing CTRL-V followed by CTRL-A
# Alternative notations for ^A:
screen -S RTORRENT -p 0 -X stuff $'\001q' # $'\001' is octal notation for CTRL-A
screen -S RTORRENT -p 0 -X stuff $'\cAq' # $'\cx' is bash notation for a control-x character
msing:

If the current directory if import for start.sh, put this line at the begin of start.sh:
cd "$(dirname "$(which "$0")")" # Go to script directory
See also: http://fvue.nl/wiki/Cd_to_script-directory
This allows passing a single command to screen:
# Start screen session `bf2screen'
screen -S BF2SCREEN -d -m /home/bf2user/gamecreate/bf2/start.sh +dedicated +lowPriority
# Stop screen session `bf2screen'
screen -S BF2SCREEN -p 0 -X stuff $'\cC'
See also:
http://fvue.nl/wiki/Screen:_Start/st...ia_one_command


Freddy Vulto
http://fvue.nl/wiki

Last edited by fvu; 08-19-2007 at 09:49 AM.
 
Old 08-19-2007, 11:08 PM   #5
msing
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
Thanks a lot for the lead. I'll play around with that code for a bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GDM/KDM Login Screen too big for screen on ATI 3D Rage Pro daemon_14 Linux - Software 0 01-14-2006 02:34 PM
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 01:10 PM
compile kernel, black screen on init scripts infamous41md Linux - Newbie 3 12-17-2004 01:24 PM
Need help running scripts from scripts sdouble Linux - Newbie 3 05-31-2004 01:56 PM
Unable to configure screen resolution for 15.2" LCD screen in Fedore Core 1 schu Linux - Newbie 3 01-02-2004 06:39 PM


All times are GMT -5. The time now is 12:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration