Create a Screen session with a bash script using crontab

77

Solution 1

Start screen in detached mode, and make it run your command inside it:

screen -d -m -S bukkit bash -c 'cd $HOME/server && java -jar bukkit.jar'

You might want to create a dedicated script bukkit.sh:

#!/bin/bash -e
cd ~/server
java -jar bukkit.jar

So that if the script becomes more complex you don't have to write a long line for screen, and so the screen command can stay the same, simply:

screen -d -m -S bukkit path/to/bukkit.sh

Solution 2

You should update-rc.d as follows to turn on service on boot:

# update-rc.d cron defaults
Share:
77
user2861783
Author by

user2861783

Updated on September 18, 2022

Comments

  • user2861783
    user2861783 over 1 year

    I have a table with a few columns. One of the column is named flight_date is varchar format.

    It has a date stored in it in format like '08/12/2015' which is mm/dd/yyyy

    I want to run a query which will return me a list of the records with date in 2016.

    Can someone help me out please.

    Thanks.

  • Maythux
    Maythux about 10 years
    @JacobLarson You are welcome.. It's better to mark as answer and upvote if this helps you
  • Jacob Larson
    Jacob Larson about 10 years
    I tried doing both options, the one with one longer file, and then the one with two separate files, but now the screen session isn't getting created at all. I've tried running the commands directly from the command line, but that didn't work either.. :/
  • janos
    janos about 10 years
    Do you get an error message or something? First get the bukkit.sh script working on the command line. Next, check that screen -S bukkit path/to/bukkit.sh works. Next, check that screen -d -m -S bukkit path/to/bukkit.sh works. Finally, setup cron. Try the most simple thing first, and take little steps so you understand which step breaks. Tell me that, and the error message you get if you need help.