LinuxQuestions.org
Visit Jeremy's Blog.
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 10-04-2011, 07:01 AM   #1
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Rep: Reputation: 15
screen and crontab...confusion


ok i know that crontab can be used to execute scripts at a set time or every x minutes....i can find loads of stuff about that but its the scripts i cant figure out

heres what i want it for

we use ubuntu and run a minecraft server (using craftbukkit)
our procedure is to load it into a screen so we can have remote access to it
all that works really well and ubuntu is wonderfully stable for it

but we need to do two things

1) every 30 minutes we need a script to:
  • gointo the screen ( screen -dr xxxx where xxxx seems to be a random number)
  • enter the following text into the screen as though it was typed save-all (ENTER KEY)

2) at 0550 every day we need a script to:
  • gointo the screen ( screen -dr xxxx where xxxx seems to be a random number)
  • enter the following text into the screen as though it was typed say server going down in 10 minutes {ENTER KEY)
  • sleep 60
  • enter the following text into the screen as though it was typed say server going down in 9 minutes {ENTER KEY)
  • sleep 60
  • ...so on till it gets to 0
  • enter the following text into the screen as though it was typed stop {ENTER KEY)
  • sleep 300
  • enter ./start.sh


now as you can see i know the wait command is sleep n (amount of seconds)
but the screen is always a random number which means any script has to have the new number entered (theres got to be an easier way).
since when you go into the screen its the console not a proper terminal session (you just type into it the same as a terminal) i dont even know if what im asking can be done

**side note**
there are tons of plugins for the software to do the save-all bit ...but as new builds are appearing weekily sometime daily lol these get broken, and a plugin uses resources, spams the console and is yet another plugin to look at when stuff goes wrong, i think crontab would be a more sensible route

thnx in advance
 
Old 10-05-2011, 08:26 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Personally, if there was a plugin available I'd use it, no point reinventing the wheel unless you can do a better job of it.
 
Old 10-05-2011, 10:49 AM   #3
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Code:
screen -ls
There are screens on:
        14330.pts-0.ns  (Detached)
        30297.pts-0.ns  (Detached)
2 Sockets in /tmp/uscreens/S-username
gives you the numbers of screen running

while you want to reattach to the screen running you commonly need only "-r" option which reattaches you to only one running screen session.

while doing this on multiple running screens:
Code:
screen -r
There are several suitable screens on:
        14330.pts-0.ns  (Detached)
        30297.pts-0.ns  (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
will need a "-dr xxx" option which was listed "-ls"

Last edited by lithos; 10-05-2011 at 10:51 AM.
 
Old 10-05-2011, 05:53 PM   #4
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by kbp View Post
Personally, if there was a plugin available I'd use it, no point reinventing the wheel unless you can do a better job of it.
problem is plugins use up memory even when not being used and thye go wrong...infact our autosave plugin is currently fubar.


@lithos (sorry i dont know how to multi quote)

thats the problem everyreboot the numbers are different so no set script could be used as each time it would be opening a different screen

i was taught to use screen -dr to list them and screen -dr xxxx (xxxx being the screeen number ) to get into them
 
Old 10-07-2011, 10:19 AM   #5
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
sorry to bump but i still have issues

lots of googling has helped but still stuck

ok ...

screen -S max creates a screen that is named max

screen -dr max connects to it

thats part of the problem solved (a major part of it)

now if i make a script that adds

screen -S max -X stuff "say testing 10 ^M"

it will send say testing 10 ^M to the screen but it just sits on the screens input line dosnt enter it (which i thought the ^M was for)

infact a little test script i made

Quote:
#!/bin/sh
screen -S max -X stuff "say testing 10 ^M"
sleep 10
screen -S max -X stuff "say testing 20 ^M"
sleep 20
screen -S max -X stuff "say testover ^M"
results in the input line reading say testing 10 ^Msay testing 20 ^Msay testover ^M

how do i make it send a return key?
 
Old 10-07-2011, 10:26 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I haven't looked at this thread in detail, but perhaps Expect would be useful to you (and it's probably already on your system, or in your distro's repositories).

Also, you have to do multi-quoting manually (i.e. going to each post, pressing the "Quote" button and copying all those into one post). Some forums have a multi-quote facility, but alas LQ is not one of them.
 
Old 10-07-2011, 10:39 AM   #7
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Nylex View Post
I haven't looked at this thread in detail, but perhaps Expect would be useful to you (and it's probably already on your system, or in your distro's repositories).

Also, you have to do multi-quoting manually (i.e. going to each post, pressing the "Quote" button and copying all those into one post). Some forums have a multi-quote facility, but alas LQ is not one of them.
have book marked that, if im unable to send a return key stroke (all im missing at mo) i will look into this further thank you

on a side note ...why call it screen!?!? why ? do they have any idea how many irelevent results google finds when you look for "screen help" "send return key to screen" *quietly sobs in the corner*
 
Old 10-07-2011, 10:40 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Maybe try googling with "GNU screen". I often have the same problem when I'm googling for information related to R (which is a language for statistics and data analysis) .
 
Old 10-07-2011, 10:51 AM   #9
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Nylex View Post
Maybe try googling with "GNU screen". I often have the same problem when I'm googling for information related to R (which is a language for statistics and data analysis) .
ouch ( http://www.google.co.uk/search?rlz=1...for+statistics ) ?

i found it!
Code:
#!/bin/sh
screen -S max -X stuff "say testing 10 "
screen -S max -X eval "stuff \015"
sleep 10
screen -S max -X stuff "say testing 20 "
screen -S max -X eval "stuff \015"
sleep 20
screen -S max -X stuff "say testover "
screen -S max -X eval "stuff \015"
now i have no idea why it works or if thiers a simplier way but its what i was able to disasemble from some examples of other scrips dotted about ...it works..i may of created a monster but it works it actualy works!!!!
 
Old 10-07-2011, 10:55 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by mrgreaper View Post
Yes. I usually write "r-project" in Google, which often helps.

Anyway, glad you found a solution to your problem. I'm not an expert with Screen, so hopefully someone else will tell you if there's a better way to do what you want .
 
Old 10-07-2011, 11:00 AM   #11
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
yep now its a case of creating test scripts that just use say commands and see if it looks all good before i use actual commands
 
  


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
crontab and screen? zssz Linux - Software 6 08-24-2012 06:07 PM
Crontab : How to add a TAB to the current running SCREEN? patrick295767 Linux - General 1 08-24-2011 05:12 PM
[SOLVED] Some crontab confusion. arashi256 Linux - Newbie 5 06-07-2010 07:24 AM
Screen with crontab noon Linux - Software 2 12-02-2005 02:21 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:56 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
Open Source Consulting | Domain Registration