LinuxQuestions.org
Help answer threads with 0 replies.
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 10-10-2011, 09:05 AM   #16
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15

Quote:
Originally Posted by chrism01 View Post
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.

Also amend cron cmd
Code:
0 5 * * * /home/minecraft/autorestart.sh >> /home/minecraft/autolog.log 2>&1
youve lost me ?

as i say the script runs perfectly when trigered from the terminal
when cron trigers it ....well it cant find screen

do you mean in my script i change
screen -S max -X stuff "say 5 "
screen -S max -X eval "stuff \015"

to

/linux/programfiles/screen/screen -S max -X stuff "say 5 "
/linux/programfiles/screen/screen -S max -X eval "stuff \015"


the /linux/programfiles/screen/ is just a guess as im not able to access the server right now to locate screen, im assuming along the line of windows the path will be similier
but then why would it work from terminal but not cron thats what i dont understand isnt cron simply automating me doing the command?




EDIT
i have an idea... i cant test at mo so please tell me if its crazy

i set cron to run this script

bypass.sh
Code:
#!/bin/sh
cd /home/minecraft/
./autorestart.sh
it would be even better if i could make it do it as user minecraft but i guess there has to be some limitations lol

would that work?

Last edited by mrgreaper; 10-10-2011 at 09:09 AM.
 
Old 10-10-2011, 09:46 AM   #17
rch
Member
 
Registered: Feb 2003
Location: Santa Clara,CA
Distribution: Mandriva
Posts: 909

Rep: Reputation: 48
No, that would be same as what you were doing earlier. The errors from screen shows that cron knows where screen is - but is not able to connect to the screen that was created earlier so that it can run commands on that screen. Like I pointed out, I don't think screen is necessary. Based on your script, the two important scripts seems to be /home/minecraft/backupserver.sh and "./start.sh" which I assume mean /home/minecraft/start.sh -which has the rsync code, yes?

So, why don't you add the two scripts directly to cron?
 
Old 10-10-2011, 10:55 AM   #18
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rch View Post
No, that would be same as what you were doing earlier. The errors from screen shows that cron knows where screen is - but is not able to connect to the screen that was created earlier so that it can run commands on that screen. Like I pointed out, I don't think screen is necessary. Based on your script, the two important scripts seems to be /home/minecraft/backupserver.sh and "./start.sh" which I assume mean /home/minecraft/start.sh -which has the rsync code, yes?

So, why don't you add the two scripts directly to cron?
no the important bits are
the telling players they have 6 minutes till the server shuts down so they can log out
making the server do the save-all
making the server do memory -f
all that as far as i know is only possible via inputting text to the screen
rsync is important too as is starting it back up but the other stuff is just as important
as i say though the script is fine its getting cron to actualy work right lol is thier an alternitve to cron?

Last edited by mrgreaper; 10-10-2011 at 11:00 AM.
 
Old 10-10-2011, 03:20 PM   #19
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,357

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
cron is the *nix scheduler. It runs as a detached process.

As above, yes you need to supply complete paths to cmds/files.
Your login env sets these up for you eg try
Code:
echo $PATH
to see what is setup when you login.
cron is much more restrictive, so either supply full paths or source the relevant parts of your login file(s) ie .bashrc, .bash_profile

Don't use screen to msg the users; use wall http://linux.die.net/man/1/wall or write http://linux.die.net/man/1/write

Every user can have a cron job if not denied by /etc/cron.deny. Just login as 'minecraft' and 'crontab -e'.
 
1 members found this post helpful.
Old 10-11-2011, 10:38 AM   #20
hen770
Member
 
Registered: Oct 2010
Distribution: Arch
Posts: 136

Rep: Reputation: 7
just an informative question, i am following that post and i am wonder what is the difference btween 2>&1 between the two files (as posted at #1) or at the end of the two files (and between them >>) ?

example:

one.sh 2>&1 two.txt

one.sh >> two.txt 2>&1
 
Old 10-11-2011, 12:09 PM   #21
rch
Member
 
Registered: Feb 2003
Location: Santa Clara,CA
Distribution: Mandriva
Posts: 909

Rep: Reputation: 48
The first one outputs both stdout and stderr to two.txt overwriting if necessary. The second one only appends to the file if there is any content left. Usually, 2>&1 can be written as &> provided the shell gives you this "shortcut".
 
Old 10-11-2011, 08:44 PM   #22
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,357

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Actually, originally the parser was strictly left-to-right, so the latter was the way to go. imho easier to read/understand.
Also, '>>' WILL create a new file if it does not already exist, otherwise it appends to it. '>' always overwrites target file.
 
Old 10-12-2011, 02:52 AM   #23
hen770
Member
 
Registered: Oct 2010
Distribution: Arch
Posts: 136

Rep: Reputation: 7
so the first one is actually write stdout & stderr to the file but show nothing on the screen ?
and the second is appending (or creating) the stdout to the file, and then show stdout and stderr on the screen ?
 
Old 10-12-2011, 05:07 AM   #24
rikxik
Member
 
Registered: Dec 2007
Posts: 88

Rep: Reputation: 19
Quote:
example:

one.sh 2>&1 two.txt
Quote:
Originally Posted by rch View Post
The first one outputs both stdout and stderr to two.txt overwriting if necessary.
No, the first one simply redirects the stderr to the same destination as stdout (which hasn't been redirected to two.txt). Consider:

Code:
$ cat one.sh
#!/usr/bin/ksh

ls non_existant_file
$ ls non_existant_file
non_existant_file: No such file or directory
$ one.sh 2>&1 two.txt
non_existant_file: No such file or directory
$ ls two.txt
two.txt: No such file or directory
In order to do that, it has to be:

Code:
one.sh 1>two.txt 2>&1

Last edited by rikxik; 10-12-2011 at 05:09 AM.
 
1 members found this post helpful.
Old 10-13-2011, 12:20 PM   #25
hen770
Member
 
Registered: Oct 2010
Distribution: Arch
Posts: 136

Rep: Reputation: 7
which is basicly the same as the second example.

Thanks.
 
  


Reply


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
Crontab is not working, the script is working arfal SUSE / openSUSE 6 02-08-2010 08:48 PM
crontab not working mahmoud Linux - Newbie 16 07-11-2008 12:46 PM
crontab not working durgap Linux - General 6 09-01-2005 02:38 PM
crontab nor working navaladi Mandriva 11 01-17-2005 06:58 AM
crontab not working subaruwrx Linux - Newbie 8 08-17-2004 09:12 PM


All times are GMT -5. The time now is 04:01 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