[SOLVED] Trying to add a cron job ~/desktop-session/startup if not already there

Forum Forums New users New Users and General Questions [SOLVED] Trying to add a cron job ~/desktop-session/startup if not already there

  • This topic has 4 replies, 3 voices, and was last updated Mar 26-8:40 am by ex_Koo.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33674
    Moderator
    BobC

      The syntax seems to be causing trouble because if I use the underlying command (starting at echo) from a terminal, it works, but not from the startup script…

      I’m trying to get it to look at the existing crontab for my user, and if “aptitude-updatescheck.sh” isn’t on any line, then use echo to add the line via std input

      test [ $(crontab -l | grep "aptitude-updatescheck.sh" | wc -l) -eq 0 ] \
      	&& (echo "*/10 * * * * env DISPLAY=:0.0 aptitude-updatescheck.sh" | crontab - )&
      

      What did I do wrong? It doesn’t add it.

      PS: I had the right syntax with if/else/fi structure (sorry, but having 2 different script languages leaves me wondering what to use), but I couldn’t figure out how to make it run in background. Maybe it doesn’t need to add to crontab in background? I’m just trying to add the job to the list if its not already there. The syntax from ask Ubuntu type posts I found didn’t work at all.

      I found that I could just do normal if/then logic and not try to do the test logic and not run it in background, and it added it to the cron job list.

      • This topic was modified 3 years, 1 month ago by BobC.
      • This topic was modified 3 years, 1 month ago by BobC.
      #33781
      Moderator
      Brian Masinick
        Helpful
        Up
        0
        ::

        I tried it and test apparently has too many arguments using this specific syntax:

        test [ $(crontab -l | grep “aptitude-updatescheck.sh” | wc -l) -eq 0 ] \
        > && (echo “*/10 * * * * env DISPLAY=:0.0 aptitude-updatescheck.sh” | crontab – )&
        [1] 8092
        masinick@mx:~/bin
        $ no crontab for masinick
        bash: line 4: test: too many arguments

        [1]+ Exit 2 test [ $(crontab -l | grep “aptitude-updatescheck.sh” | wc -l) -eq 0 ] && ( echo “*/10 * * * * env DISPLAY=:0.0 aptitude-updatescheck.sh” | crontab – )

        --
        Brian Masinick

        #33782
        Moderator
        Brian Masinick
          Helpful
          Up
          0
          ::

          To be honest with you, I personally prefer syntax that uses the regular if/then logic, and I generally do not use test or [ ] logic by itself because I usually have to look up what it means, whereas I can almost always figure out if … then commands unless some other strange construct is embedded within them.

          Perl is one language that you can go crazy with shorthand; I use longer syntax whenever possible for clarity.
          sed and awk are very similar – and a lot of Perl shorthand actually comes from their very arcane, questionable syntax.

          --
          Brian Masinick

          #33790
          Moderator
          BobC
            Helpful
            Up
            0
            ::

            I agree. I don’t like any more complexity than needed. Because all the logic in it was done with test, I didn’t know that if/fi logic would work. The more syntax you try to learn, the more murky it all becomes.

            #33851
            Member
            ex_Koo
              Helpful
              Up
              0
              ::

              apt-get dist-upgrade -s –quiet=2 | grep ^Inst | wc -l

            Viewing 5 posts - 1 through 5 (of 5 total)
            • You must be logged in to reply to this topic.