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.
i used sudo crontab -e to load it
i choose nano as my editor (i get on with nano...vi hates me)
i want the script called autorestart.sh thats in the home folder of a user called mine craft to run every day at 0500 and to start with output to autolog.log
# 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
0 5 * * * /home/minecraft/autorestart.sh 2>&1 >> /home/minecraft/autolog.log
as i understood it
0(minutes) 5(5 am) *(every day of the month) *(everymonth) *(every day) /home/minecraft/autorestart.sh(the script) 2>&1 >>(i have no idea?) /home/minecraft/autolog.log(where u want it to send screen output to)
but at 5am nothing happened
i went to check the autolog.log....there is no autolog.log so im guessing it hadnt even attempted the line!
i thought maybe its because its decided to save it in a tmp folder (at the top of nano it says /tmp/crontab.xqAb3k/crontab but then if it sudo crontab -e can read it and bring the changes back up then crontab should as well?
Is crond running? Which distribution? Did you do chmod a+x on autorestart.sh? Does your script start with the standard shebang?
crond running.... no idea though if i can issue sudo crontab -e surely that means its running?
distribution: ubunutu 64bit, terminal access only (were running a minecraft server that i use putty access to)
the script is chmod 777 i have tested it seperatly with ./autorestart.sh and it runs perfectly
shebang? i feel it has a certain kabow but i may be bias as i created it ....
Code:
#!/bin/sh
screen -S max -X stuff "say nightly back up in 6 minutes Please log off"
screen -S max -X eval "stuff \015"
sleep 5
screen -S max -X stuff "say Max apologises for the inconvience"
screen -S max -X eval "stuff \015"
sleep 5
screen -S max -X stuff "say down time liable to be short"
screen -S max -X eval "stuff \015"
sleep 50
screen -S max -X stuff "say server shutdown for backup in 5 minutes"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 4 minutes"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 3 minutess"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 2 minutess"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 1 munute"
screen -S max -X eval "stuff \015"
sleep 30
screen -S max -X stuff "save-all"
screen -S max -X eval "stuff \015"
sleep 10
screen -S max -X stuff "say server shutdown for backup in 30 seconds"
screen -S max -X eval "stuff \015"
sleep 20
screen -S max -X stuff "say 10 seconds... log out now"
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 9 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 8 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 7 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 6 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 5 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 4 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 3 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "memory -f"
screen -S max -X eval "stuff \015"
sleep 3
screen -S max -X stuff "say 2 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 1 "
screen -S max -X eval "stuff \015"
sleep 1
# screen -S max -X stuff "say if only we had a kick all command"
# screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "stop"
screen -S max -X eval "stuff \015"
sleep 30
/home/minecraft/backupserver.sh
screen -S max -X stuff "./start.sh "
screen -S max -X eval "stuff \015"
sleep 2
Even if you are able to issue crontab -e, crond may not be running. A simple
Code:
ps aux|grep crond
should tell you whether crond is running or not. Also check /var/log/crond.
Quote:
Originally Posted by mrgreaper
crond running.... no idea though if i can issue sudo crontab -e surely that means its running?
distribution: ubunutu 64bit, terminal access only (were running a minecraft server that i use putty access to)
the script is chmod 777 i have tested it seperatly with ./autorestart.sh and it runs perfectly
shebang? i feel it has a certain kabow but i may be bias as i created it ....
Code:
#!/bin/sh
screen -S max -X stuff "say nightly back up in 6 minutes Please log off"
screen -S max -X eval "stuff \015"
sleep 5
screen -S max -X stuff "say Max apologises for the inconvience"
screen -S max -X eval "stuff \015"
sleep 5
screen -S max -X stuff "say down time liable to be short"
screen -S max -X eval "stuff \015"
sleep 50
screen -S max -X stuff "say server shutdown for backup in 5 minutes"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 4 minutes"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 3 minutess"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 2 minutess"
screen -S max -X eval "stuff \015"
sleep 60
screen -S max -X stuff "say server shutdown for backup in 1 munute"
screen -S max -X eval "stuff \015"
sleep 30
screen -S max -X stuff "save-all"
screen -S max -X eval "stuff \015"
sleep 10
screen -S max -X stuff "say server shutdown for backup in 30 seconds"
screen -S max -X eval "stuff \015"
sleep 20
screen -S max -X stuff "say 10 seconds... log out now"
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 9 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 8 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 7 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 6 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 5 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 4 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 3 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "memory -f"
screen -S max -X eval "stuff \015"
sleep 3
screen -S max -X stuff "say 2 "
screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "say 1 "
screen -S max -X eval "stuff \015"
sleep 1
# screen -S max -X stuff "say if only we had a kick all command"
# screen -S max -X eval "stuff \015"
sleep 1
screen -S max -X stuff "stop"
screen -S max -X eval "stuff \015"
sleep 30
/home/minecraft/backupserver.sh
screen -S max -X stuff "./start.sh "
screen -S max -X eval "stuff \015"
sleep 2
sorry but i looked at loads of crontab guides and they all seem to assume that crontab is loaded and running by default
/var/log/crond. didnt exist, infact no file starting cron at all
i have used linux on and off for 5 years, more off then on and i still find it serously confusing, however now i know what a shebang is (i actualy thought you guys were playing the lets confuse the newbie came, like asking a builders apprentice for a left handed screwdriver...sorry for my kapow reply)
- for Ubuntu. If it returns two lines, then crond is running fine. And there is no /var/log/crond in Ubuntu. Most likely, the log for cron is /var/log/syslog. So, do
Code:
less /var/log/syslog|grep -i cron
to see if you can find what is happening.
Quote:
i have used linux on and off for 5 years, more off then on and i still find it serously confusing, however now i know what a shebang is (i actualy thought you guys were playing the lets confuse the newbie came, like asking a builders apprentice for a left handed screwdriver...sorry for my kapow reply)
I have been using Linux for 12 years and I also find it confusing at times. So, don't worry. That's why Google and LinuxQuestions exist, don't you think?
- for Ubuntu. If it returns two lines, then crond is running fine. And there is no /var/log/crond in Ubuntu. Most likely, the log for cron is /var/log/syslog. So, do
Code:
less /var/log/syslog|grep -i cron
to see if you can find what is happening.
I have been using Linux for 12 years and I also find it confusing at times. So, don't worry. That's why Google and LinuxQuestions exist, don't you think?
AHA
i have found the problem,sort of though not the solution
when i run the script autorestart with ./autorestart.sh all is fine it works great
but the output from autolog.log (i created it and now its being used) is full off..
Quote:
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
No screen session found.
is it due to the fact user minecraft created the screen...the script is being run by user root cant see it?
if so how do i make user root see it?
Why run rsync using screen? Beats me. Why you don't just run the script that has the rsync (which appears to do the real work) from your cron?
because if we rsync while the server is active bad things happen, better to bring it down first
we also want the server to be brought down for more then backup, so it can have that fresh just started server feel to the players every day
screens are needed too as we remote into it using putty and similier
The default cron env is minimal; you should use full absolute paths to every cmd & file referenced, or set up the correct env (eg via 'source' cmd) at the top of your shell script (after #!/bin/bash) on next line(s).
See /var/log/cron (at least on RH) for cron msgs.
Also, if cron itself has an issue, it'll email the job owner or root.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.