ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Crontab troubleshooting

    IT Discussion
    ubuntu 14.04 crontab
    3
    20
    3.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Sparkum
      last edited by Sparkum

      Hey guys.

      So lately I've been working on using cron jobs,

      I've got it working on one of my boxes just fine, and doing another one on another box, looking essentially identical and nothing.

      I've been googling but everyone's suggestions arent working.

      So when I run the command sh /home/sparkum/cron/job.sh it works just fine

      Under the crontab

       * * * * * /home/sparkum/cron/job.sh 
      

      but nothing happens.

      I've given it chmod 0755 and chmod +x .... nothing

      folder has 777

      I was looking at the logs (cant find the command now) and it was only showing my edits

      cron job is running, I have reset it several time.

      Anyone have any suggestions?

      I've tried running it both under root and my sudo user sparkum

      A scottalanmillerS 2 Replies Last reply Reply Quote 0
      • A
        Alex Sage @Sparkum
        last edited by Alex Sage

        @Sparkum Silly Questions.

        Is the script there? Can you run the script manually? Does it work?

        scottalanmillerS 1 Reply Last reply Reply Quote 1
        • scottalanmillerS
          scottalanmiller @Alex Sage
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @Sparkum
            last edited by

            @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.

            S 1 Reply Last reply Reply Quote 1
            • S
              Sparkum @scottalanmiller
              last edited by

              @scottalanmiller

              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?

              scottalanmillerS 2 Replies Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @Sparkum
                last edited by

                @Sparkum said in Crontab troubleshooting:

                @scottalanmiller

                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.

                1 Reply Last reply Reply Quote 0
                • scottalanmillerS
                  scottalanmiller @Sparkum
                  last edited by

                  @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.

                  S 1 Reply Last reply Reply Quote 1
                  • S
                    Sparkum @scottalanmiller
                    last edited by

                    @scottalanmiller

                    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 service

                    Nothing triggering from cron though still

                    scottalanmillerS 1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller @Sparkum
                      last edited by

                      @Sparkum said in Crontab troubleshooting:

                      @scottalanmiller

                      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."

                      1 Reply Last reply Reply Quote 0
                      • scottalanmillerS
                        scottalanmiller
                        last edited by

                        sh is normally an alias of bash.

                        1 Reply Last reply Reply Quote 0
                        • S
                          Sparkum
                          last edited by

                          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....

                          scottalanmillerS 1 Reply Last reply Reply Quote 0
                          • S
                            Sparkum
                            last edited by

                            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
                            
                            1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller @Sparkum
                              last edited by

                              @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?

                              1 Reply Last reply Reply Quote 0
                              • scottalanmillerS
                                scottalanmiller
                                last edited by

                                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.

                                S 1 Reply Last reply Reply Quote 1
                                • S
                                  Sparkum @scottalanmiller
                                  last edited by

                                  @scottalanmiller

                                  Simply to check if a service is running, if it is do nothing,

                                  If the service has stopped, to start it.

                                  scottalanmillerS 1 Reply Last reply Reply Quote 0
                                  • scottalanmillerS
                                    scottalanmiller @Sparkum
                                    last edited by

                                    @Sparkum said in Crontab troubleshooting:

                                    @scottalanmiller

                                    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?

                                    S 1 Reply Last reply Reply Quote 0
                                    • S
                                      Sparkum @scottalanmiller
                                      last edited by

                                      @scottalanmiller

                                      Simply chalk it up to me learning.

                                      If you wouldnt mind throwing me in the right direction I'll be on my way haha

                                      1 Reply Last reply Reply Quote 0
                                      • scottalanmillerS
                                        scottalanmiller
                                        last edited by

                                        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.

                                        S 1 Reply Last reply Reply Quote 0
                                        • S
                                          Sparkum @scottalanmiller
                                          last edited by

                                          @scottalanmiller
                                          Using Ubuntu 14.04

                                          scottalanmillerS 1 Reply Last reply Reply Quote 0
                                          • scottalanmillerS
                                            scottalanmiller @Sparkum
                                            last edited by

                                            @Sparkum said in Crontab troubleshooting:

                                            @scottalanmiller
                                            Using Ubuntu 14.04

                                            Oh 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

                                            1 Reply Last reply Reply Quote 0
                                            • 1 / 1
                                            • First post
                                              Last post