LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-28-2014, 11:02 AM   #1
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Rep: Reputation: 3
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.

Last edited by EODSteven; 04-28-2014 at 11:08 AM. Reason: Added Information
 
Old 04-28-2014, 11:47 AM   #2
JeremyBoden
Member
 
Registered: Nov 2011
Posts: 939

Rep: Reputation: 174Reputation: 174
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).
 
Old 04-28-2014, 11:58 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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.

Last edited by schneidz; 04-28-2014 at 12:54 PM.
 
Old 04-28-2014, 02:33 PM   #4
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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

Last edited by EODSteven; 04-28-2014 at 02:54 PM. Reason: added quote
 
Old 04-28-2014, 02:37 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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 View Post
...
# 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.

Last edited by schneidz; 04-28-2014 at 02:44 PM.
 
Old 04-28-2014, 02:46 PM   #6
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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

Last edited by EODSteven; 04-28-2014 at 02:50 PM. Reason: Added Information
 
Old 04-28-2014, 02:58 PM   #7
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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.

Last edited by EODSteven; 04-28-2014 at 03:01 PM. Reason: Added Information
 
Old 04-28-2014, 03:13 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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.
 
Old 04-28-2014, 03:17 PM   #9
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
No, I'm sorry I forgot to mention that...I'll try it in a regular user crontab and see if it does.....
 
Old 04-28-2014, 03:26 PM   #10
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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.

Last edited by EODSteven; 04-28-2014 at 03:33 PM. Reason: Added Information
 
Old 04-28-2014, 03:27 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.

Last edited by suicidaleggroll; 04-28-2014 at 03:30 PM.
 
Old 04-28-2014, 03:38 PM   #12
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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:~$

Last edited by EODSteven; 04-28-2014 at 03:46 PM. Reason: Added Information
 
Old 04-28-2014, 03:49 PM   #13
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.
 
Old 04-28-2014, 03:57 PM   #14
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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.

Last edited by EODSteven; 04-28-2014 at 03:58 PM.
 
Old 04-28-2014, 04:03 PM   #15
EODSteven
Member
 
Registered: Oct 2012
Location: Manchester, Tn
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196

Original Poster
Rep: Reputation: 3
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!

Last edited by EODSteven; 04-28-2014 at 04:05 PM. Reason: Added Information
 
  


Reply

Tags
crontab


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
Script is not running in Crontab Deepesh_tr Linux - Newbie 8 09-02-2012 08:43 PM
Crontab not running script j8177e5 Linux - Newbie 2 12-21-2010 09:54 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 04:49 PM
crontab not running script sunlinux Linux - Newbie 5 05-18-2010 07:21 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 09:48 PM


All times are GMT -5. The time now is 04:41 AM.

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