Crontab troubleshooting
-
@Sparkum Silly Questions.
Is the script there? Can you run the script manually? Does it work?
-
@aaronstuder said in Crontab troubleshooting:
@Sparkum Silly Questions.
Is the script there? Can you run the script manually? Does it work?
He mentioned that it works.
-
@Sparkum said in Crontab troubleshooting:
So when I run the command sh /home/sparkum/cron/job.sh it works just fine
That's not identical to what you have in the cronjob. You are not pumping it into a shell in cron.
-
Ya I realize they arent identical, but do I need the leading "sh" in the cron?
As I've only done it once I'm simply comparing it to what I've done, and what I'm finding on google, but both I'm not seeing the leading "sh"
I did just notice its bash...
#!/bin/bash
I assume that will have some compact?
-
@Sparkum said in Crontab troubleshooting:
Ya I realize they arent identical, but do I need the leading "sh" in the cron?
As I've only done it once I'm simply comparing it to what I've done, and what I'm finding on google, but both I'm not seeing the leading "sh"
I did just notice its bash...
#!/bin/bash
I assume that will have some compact?
If you need it to run from the command line, you certainly need it from cron. You aren't testing the same thing that you are running. That you added "sh" to the beginning implies that you don't expect it to run from cron either.
-
@Sparkum said in Crontab troubleshooting:
As I've only done it once I'm simply comparing it to what I've done, and what I'm finding on google, but both I'm not seeing the leading "sh"
You basically never use a leading sh, you put in a she-bang header like you show. But you can't test by adding an sh either.
-
So since noticing its a bash script (the script is to check if a service is running, if it does it echos "service is running" if not it starts the service.
So being that its a bash script should I run
bash /home/sparkum/job.sh
should I rename it to job.bash?
when I run it with bash /home/sparkum/job/.sh it echo's its running (which its not)
when I run with sh it starts the serviceNothing triggering from cron though still
-
@Sparkum said in Crontab troubleshooting:
So since noticing its a bash script (the script is to check if a service is running, if it does it echos "service is running" if not it starts the service.
So being that its a bash script should I run
bash /home/sparkum/job.sh
If you have to run ANY shell in front of the script, it's not going to work in cron. You aren't doing that in cron. They must be identical, not "similar."
-
sh is normally an alias of bash.
-
So if I run
/home/sparkum/cron/job.sh
I get the output that the service is running (which it isnt)
if I run
sh /home/sparkum/cron/job.sh
it says
/home/sparkum/cron/job.sh: 4: /home/sparkum/cron/job/sh: 5: not round starting service
and then all is working....
-
Script I'm using is
#!/bin/bash service=replace_me_with_a_valid_service if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then echo "$service is running!!!" else /etc/init.d/$service start fi
-
@Sparkum said in Crontab troubleshooting:
So if I run
/home/sparkum/cron/job.sh
I get the output that the service is running (which it isnt)
if I run
sh /home/sparkum/cron/job.sh
it says
/home/sparkum/cron/job.sh: 4: /home/sparkum/cron/job/sh: 5: not round starting service
and then all is working....
So something is wrong with your script, then. You need to fix the script so that it works properly before talking about scheduling it. Why is it giving bad output when run as intended?
-
Before we fix this, let's step back. What is the goal here, this does not feel like the right way to be approaching the problem.
-
Simply to check if a service is running, if it is do nothing,
If the service has stopped, to start it.
-
@Sparkum said in Crontab troubleshooting:
Simply to check if a service is running, if it is do nothing,
If the service has stopped, to start it.
Then why use a script rather than using an industry standard tool for that? Like having the system keep it running itself or using something built for this? Why reinvent the wheel?
-
Simply chalk it up to me learning.
If you wouldnt mind throwing me in the right direction I'll be on my way haha
-
Even if you do want to reinvent the wheel.... the OS has tools for that, too. You are at the mercy of things with service in their names. That's not good.
What OS are you on? /etc/init.d is deprecated.
-
@scottalanmiller
Using Ubuntu 14.04 -
@Sparkum said in Crontab troubleshooting:
@scottalanmiller
Using Ubuntu 14.04Oh okay, probably on the legacy system still then. In that case, what you are looking to do is better done with...
/etc/init.d/servicename status