Why is this happening? (bash script + cron question)

Ask questions about dedicated servers here and we and other users will do our best to answer them. Please also refer to the self-help section for tutorials and answers to the most commonly asked questions.
Post Reply
WoAyumi
A regular
A regular
Posts: 52
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Sat Apr 28, 2012 6:24 pm

Why is this happening? (bash script + cron question)

Post by WoAyumi »

Hey guys!

I have this self-made script and it does work well and performs all actions, if it is started manually, however, it does not perform the action from line 81, if it is automatically started from cron.

I don't understand, why.
Any thoughts?

http://pastie.org/private/9duxtwkcqwgnrgh2cn3dng


Thank you! :wink:
User avatar
Edge100x
Founder
Founder
Posts: 13112
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Why is this happening? (bash script + cron question)

Post by Edge100x »

Does it work outside cron?

Have you tried using the full path to Java?
WoAyumi
A regular
A regular
Posts: 52
Joined: Sat Apr 28, 2012 6:24 pm

Re: Why is this happening? (bash script + cron question)

Post by WoAyumi »

Yes, script works and starts the server, when initiated manually.
How do I add java location?
User avatar
Edge100x
Founder
Founder
Posts: 13112
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Why is this happening? (bash script + cron question)

Post by Edge100x »

"which java" will show you where the executable is located.
WoAyumi
A regular
A regular
Posts: 52
Joined: Sat Apr 28, 2012 6:24 pm

Re: Why is this happening? (bash script + cron question)

Post by WoAyumi »

it says /usr/bin/java

Where do I put it? Should I add -cp /usr/bin/java ?
User avatar
Edge100x
Founder
Founder
Posts: 13112
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Why is this happening? (bash script + cron question)

Post by Edge100x »

I suggest that you try replacing "java" with "/usr/bin/java".
WoAyumi
A regular
A regular
Posts: 52
Joined: Sat Apr 28, 2012 6:24 pm

Re: Why is this happening? (bash script + cron question)

Post by WoAyumi »

Ok, it didn't helped. java app still does not want to start from script, via cron job.
User avatar
Edge100x
Founder
Founder
Posts: 13112
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Why is this happening? (bash script + cron question)

Post by Edge100x »

I recommend that you do some tests with simpler commands to try to narrow down where the mistake is. Replace the java line with having it echo something, for instance, or remove the "nice" bit. Make sure that the command runs on its own when it's not started through cron. Remove the unnecessary quotation marks from around "mc".
WoAyumi
A regular
A regular
Posts: 52
Joined: Sat Apr 28, 2012 6:24 pm

Re: Why is this happening? (bash script + cron question)

Post by WoAyumi »

I removed quotes, I removed nice. Nothing helps. Maybe, problem is with sudo?
What else can I do?

Thank you for helping me :!:
WoAyumi
A regular
A regular
Posts: 52
Joined: Sat Apr 28, 2012 6:24 pm

Re: Why is this happening? (bash script + cron question)

Post by WoAyumi »

java runs from that script, if it is not initiated by cron.
Is cron a different user with different permissions or something?
User avatar
Edge100x
Founder
Founder
Posts: 13112
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Why is this happening? (bash script + cron question)

Post by Edge100x »

Cron runs as the same user.

You'll need to keep troubleshooting and trying different things -- that's what I would do. Try running a bash script instead. Try running "echo". Keep paring things down until you find what about that line is causing the problem, and then focus on working around that.
Post Reply