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.
-
AuthorPosts
-
March 22, 2020 at 12:12 am #33674Moderator
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.
March 24, 2020 at 3:12 pm #33781Moderator
Brian Masinick
::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 MasinickMarch 24, 2020 at 3:16 pm #33782Moderator
Brian Masinick
::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 MasinickMarch 24, 2020 at 9:03 pm #33790ModeratorBobC
::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.
March 26, 2020 at 8:40 am #33851Memberex_Koo
-
AuthorPosts
- You must be logged in to reply to this topic.