LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   crontab -e not running @reboot script (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-e-not-running-%40reboot-script-4175503229/)

EODSteven 04-28-2014 10:02 AM

crontab -e not running @reboot script
 
Hello, Just installed Ubuntu 14.04 and I'm trying to get crontab to excute a script at reboot that will run in a detached screen. For example, I run a game server and when the power goes off I want the machine to excute the script automatically when it reboots to the login prompt. I have tried crontab -e @reboot path/to/script sudo crontab -e path/to script I put the script in the home dir and did ~/ sh scrptname.sh...Any ideas?

Here's my latest attempt using sudo crontab -e
@reboot ~/sh craftbukkit.sh

...that doesn't work
I have already tried just a regular crontab -e
@reboot /home/steve/craftbukkit.sh

....that doesn't work either, and yes the script is executable.

JeremyBoden 04-28-2014 10:47 AM

If it is a user crontab, it already knows the path to your home directory.
I tend to put
Code:

@reboot sh /home/steve/craftbukkit.sh
or
@reboot sh ~/craftbukkit.sh

(even for BASH scripts).
Personally, I've never had a use for the @reboot option (yet).

schneidz 04-28-2014 10:58 AM

does something like this provide anything useful:
Code:

@reboot /bin/echo hello-world > ~/reboot.test
please provide the output of
Code:

crontab -l
ll /home/steve/craftbukkit.sh
cat /home/steve/craftbukkit.sh

so we can diag.

EODSteven 04-28-2014 01:33 PM

Quote:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* */1 * * * python /home/steve/update_dns.sh
@reboot ~/sh craftbukkit.sh
This is the sudo crontab -l

Quote:

-rwxr-xr-x 1 steve steve 445 Apr 28 09:31 /home/steve/craftbukkit.sh*
Quote:

#!/bin/bash
BINDIR=$(dirname "$(readlink -fn "$0")")
cd "$BINDIR"
cd /home/steve/craftbukkit/
screen -dmS craftbukkit java -server -Xmx5120M -Xms5120M -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+AggressiveOpts -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:LargePageSizeInBytes=4m -jar craftbukkit.jar -o true

schneidz 04-28-2014 01:37 PM

please use code tags. what are trying to run and who are you trying to run it as. i assume you know that preceding a command with sudo will attempt to run it as root ?
Quote:

Originally Posted by EODSteven (Post 5160689)
...
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* */1 * * * python /home/steve/update_dns.sh
@reboot ~/sh craftbukkit.sh

This is the sudo crontab -l
...

i think this would be interpreted as:
Code:

/root/sh /craftbukkit.sh
cron doesnt inherit environment variables (sudh as $PATH) so it is a good idea to use /full/path/to/files within your crontab as well as in the scripts that are being called from cron.

EODSteven 04-28-2014 01:46 PM

That was just my latest attempt to try to get it to work, I started out just running it as a regular user crontab and had no success. As I noted in my previous post I have already tried running crontab -e, then typing
Quote:

@reboot /home/steve/craftbukkit.sh
Quote:

@reboot sh /home/steve/craftbukkit.sh
Quote:

@reboot /home/steve/sh craftbukkit.sh

EODSteven 04-28-2014 01:58 PM

Maybe this feature has been disabled in the new Ubuntu 14.04 server due to security concerns. I have read post of creating a startup process in init.d and making symbollic links but I'm not that well versed in that sort of thing yet.

If I call the script from the terminal command line it works perfecdtly, I do have the option of logging in automatically and using the startup applications from the GUI but of course that presents security concerns as well.

schneidz 04-28-2014 02:13 PM

does this test create the file:
Code:

@reboot /bin/echo hello-world > ~/reboot.test
?

methinks you have to fill in the paths of the things you are calling.

EODSteven 04-28-2014 02:17 PM

No, I'm sorry I forgot to mention that...I'll try it in a regular user crontab and see if it does.....

EODSteven 04-28-2014 02:26 PM

Yep, It made the txt file in my home directory....
Code:

@reboot sh /home/steve/craftbukkit.sh
@reboot /bin/echo hello-world > ~/reboot.test

I knew the crontab was working because every time my IP address changes it resolves it to my domain name with that update-dns.sh file.

...but I still have no script running detached :(

what if I bash it?
that certainly works from the command line...
Quote:

steve@eodsteven:~$ bash craftbukkit.sh
steve@eodsteven:~$ screen -ls
There is a screen on:
2756.craftbukkit (04/28/2014 02:29:29 PM) (Detached)
1 Socket in /var/run/screen/S-steve.

suicidaleggroll 04-28-2014 02:27 PM

Ok, first off, does your craftbukkit.sh script need to be run with sudo/root privileges?

If the answer to that is no, then don't put it in sudo/root's crontab, you're just unnecessarily complicating things. If you want to run it as steve, then put it in steve's crontab.

Second, why are you running /home/steve/sh in that latest attempt? Do you have an sh executable located in /home/steve? If the answer to that is no (it almost certainly is), then that command will do nothing but throw an error. If you can't run the command you enter, then neither can the cron. I understand you're frustrated, but putting nonsense in the crontab will just waste time and frustrate you even more. Before you put any entry in the cron, you should first do the following:
Code:

export PATH=/usr/bin:/bin
<commandyouplantorun>

See if it even runs from the command line. If it doesn't, there's no way it's going to work in the cron.

EODSteven 04-28-2014 02:38 PM

I must of posted the previous thread right when you were typing this one.....

Also the @reboot bash craftbukkit.sh didn't work either.
Code:

teve@eodsteven:~$ screen -ls
No Sockets found in /var/run/screen/S-steve.

I put the script in my home directory and if I type sh craftbukkit.sh or bash craftbukkit.sh it runs in a detached screen just like I need it too. What I want is if the power goes off and the computer reboots that the startup sequence run that script in a detached screen, which is already in my script file. I am under the assumptiontion that crontab -e is capable of this.

And yes it works perfect from command line...
Quote:

steve@eodsteven:~$ screen -ls
No Sockets found in /var/run/screen/S-steve.

steve@eodsteven:~$ export PATH=/usr/bin:/bin
steve@eodsteven:~$ sh craftbukkit.sh
steve@eodsteven:~$ screen -ls
There is a screen on:
2809.craftbukkit (04/28/2014 02:45:44 PM) (Detached)
1 Socket in /var/run/screen/S-steve.

steve@eodsteven:~$

suicidaleggroll 04-28-2014 02:49 PM

have you run "mail" to see if you're getting any error messages from the script?

You could also append "> ~/craftbukkit.out 2>&1" to the end of your entry, so it looks like:
Code:

@reboot sh /home/steve/craftbukkit.sh > /home/steve/craftbukkit.out 2>&1
That will log all output (print messages and errors) into the /home/steve/craftbukkit.out file.

EODSteven 04-28-2014 02:57 PM

craftbukkit.out says...
Quote:

cannot make directory '/var/run/screen': Permission denied
Also, is there a way to test crontab without rebooting everytime?

so now were back to super user again.

EODSteven 04-28-2014 03:03 PM

Yikes this is a bug that has already been reported but its a million years old....
Code:

Cannot make directory '/var/run/screen': Permission denied (convert init to upstart)

    Ubuntu
    “screen” package
    Bugs
    Bug #574773

Reported by Scott Moser on 2010-05-03
136
This bug affects 24 people
Affects        Status        Importance        Assigned to        Milestone
​        screen (Ubuntu)       
Fix Released
       
Medium
        Dustin Kirkland        
​        Lucid       
Fix Released
       
Medium
        Dustin Kirkland        
Ubuntu lucid-updates
Also affects project (?) Also affects distribution/package Nominate for series
Bug Description

Binary package hint: screen

On a freshly booted server install:

$ screen -ls
Cannot make directory '/var/run/screen': Permission denied

This can be fixed with:
$ sudo /etc/init.d/screen-cleanup start

I believe this is because
/etc/rcS.d/S70screen-cleanup is running via upstart much earlier than it expects to have run, and is failing to correctly clean up that directory.

ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: screen 4.0.3-14ubuntu1
ProcVersionSignature: Ubuntu 2.6.32-21.32-server 2.6.32.11+drm33.2
Uname: Linux 2.6.32-21-server x86_64
Architecture: amd64
Date: Mon May 3 16:45:10 2010
ProcEnviron:
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: screen

I'm trying their fix and will report back ASAP!


All times are GMT -5. The time now is 02:38 AM.