Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Rep:
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 10:08 AM.
Reason: Added Information
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Original Poster
Rep:
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*
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
...
# 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.
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Original Poster
Rep:
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 01:50 PM.
Reason: Added Information
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Original Poster
Rep:
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 02:01 PM.
Reason: Added Information
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Original Poster
Rep:
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 02:33 PM.
Reason: Added Information
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 02:30 PM.
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Original Poster
Rep:
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 02:46 PM.
Reason: Added Information
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Original Poster
Rep:
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 03:05 PM.
Reason: Added Information
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.