Crontab troubleshooting
-
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