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

    Handy Utility in Linux for Logging and Question

    Scheduled Pinned Locked Moved IT Discussion
    10 Posts 3 Posters 1.4k Views
    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.
    • thanksajdotcomT
      thanksajdotcom
      last edited by

      So I have a few cron jobs that I run on my LAMP server, which is Ubuntu 14.04 LTS. Anyways, the issue I've had is that I capture the output of and log, just for my own record keeping purposes. My crontab for this job looks like this:

      */15 * * * * bash /home/aj/scripts/aj-update-wordpress | ts >> /var/log/aj_cron/update_wordpress.log 2>&1
      

      So I run this every fifteen minutes, which is overkill at the moment but I'm testing something. I'm still a little new to crontab so I bash my script, and I pipe it into the command "ts". What that is for is giving each line of output a timestamp. It is a handy utility that comes packaged with the moreutils package, which you can install with this:

      apt-get install moreutils
      

      It's really nice and I thought I'd share. Sample output:

      Jan 02 19:35:39 Success: WordPress is at the latest version.
      Jan 02 19:35:39 Success: Updated 0/0 themes.
      Jan 02 19:35:39 Success: Updated 0/0 plugins.
      Jan 02 19:35:40 Success: WordPress is at the latest version.
      Jan 02 19:35:41 Success: Updated 0/0 themes.
      Jan 02 19:35:41 Success: Updated 0/0 plugins.
      Jan 02 19:35:42 Success: WordPress is at the latest version.
      Jan 02 19:35:43 Success: Updated 0/0 themes.
      Jan 02 19:35:43 Success: Updated 0/0 plugins.
      

      However, I am having one issue with the cron job. When I run the command that is in the cron job...

      bash /home/aj/scripts/aj-update-wordpress | ts >> /var/log/aj_cron/update_wordpress.log 2>&1
      

      ...manually, it works fine. Great in fact! However, the cron job throws an error, which I can see in the log. I deleted the old log file before I realized I should have kept it, but first let me show you the script:

      #!/bin/sh
      cd /var/www/builtbyart.com
      wp core update --allow-root
      wp theme update --all --allow-root
      wp plugin update --all --allow-root
      
      cd /var/www/literaryworksbyaj.com
      wp core update --allow-root
      wp theme update --all --allow-root
      wp plugin update --all --allow-root
      
      cd /var/www/thanksaj.com
      wp core update --allow-root
      wp theme update --all --allow-root
      wp plugin update --all --allow-root
      

      The wp is a command which I got from here: http://wp-cli.org/

      It's a way to completely manage Wordpress via the CLI. When I execute the script manually, it works great! Again, however, the cron job was seemingly unable to find or execute "wp", which is located in /usr/local/bin/. Any suggestions?

      Thanks!
      A.J.

      1 Reply Last reply Reply Quote 1
      • NetworkNerdN
        NetworkNerd
        last edited by

        Does the user under which the cron job is running have the proper access to the directory you mention here?

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • thanksajdotcomT
          thanksajdotcom
          last edited by

          I'm running this through crontab, which I ran while in su mode, so full root. Definitely has permissions.

          1 Reply Last reply Reply Quote 0
          • thanksajdotcomT
            thanksajdotcom
            last edited by

            @scottalanmiller , where are you? Come out and play!

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

              @NetworkNerd said:

              Does the user under which the cron job is running have the proper access to the directory you mention here?

              Yes, cron runs as the user in question. Every user has access to cron.

              thanksajdotcomT 1 Reply Last reply Reply Quote 0
              • thanksajdotcomT
                thanksajdotcom @scottalanmiller
                last edited by

                @scottalanmiller said:

                @NetworkNerd said:

                Does the user under which the cron job is running have the proper access to the directory you mention here?

                Yes, cron runs as the user in question. Every user has access to cron.

                Any ideas why it doesn't work as a cron job but works when I run it manually?

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

                  Why does the word "bash" precede the script? The shell is all ready specified inside of the script. Remove that. You might have a pathing issue.

                  thanksajdotcomT 1 Reply Last reply Reply Quote 0
                  • thanksajdotcomT
                    thanksajdotcom @scottalanmiller
                    last edited by

                    @scottalanmiller said:

                    Why does the word "bash" precede the script? The shell is all ready specified inside of the script. Remove that. You might have a pathing issue.

                    Path is fine. It now reads as such in the crontab...

                    * */6 * * * /home/aj/scripts/aj-update-wordpress | ts >> /var/log/aj_cron/update_wordpress.log 2>&1
                    
                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller
                      last edited by

                      Same issue still?

                      thanksajdotcomT 1 Reply Last reply Reply Quote 0
                      • thanksajdotcomT
                        thanksajdotcom @scottalanmiller
                        last edited by

                        @scottalanmiller said:

                        Same issue still?

                        The logging doesn't appear to be working at all right now, which is weird.

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