0

My hosting provider panel doesn't allow to add next cron job command:

"/home/username/.acme.sh"/acme.sh --cron --home "/home/username/.acme.sh" > /dev/null

due to 'Some characters are not allowed for cron job command' error.

After reading this post about it I'm trying to understand how to run it from a script (~/run-acme.sh) and add it to a cron job but don't know how to do it (the example is using a PHP script).

Here's the content of the run-acme.sh script but don't know what to write before the command (source, . or bash) as this answer suggests:

Option 1:

#!/usr/bin/bash
bash "/home/username/.acme.sh"/acme.sh --cron --home "/home/username/.acme.sh" > /dev/null

Option 2:

#!/usr/bin/bash
source "/home/username/.acme.sh"/acme.sh --cron --home "/home/username/.acme.sh" > /dev/null

Option 3:

#!/usr/bin/bash
. "/home/username/.acme.sh"/acme.sh --cron --home "/home/username/.acme.sh" > /dev/null

Which of these options will work? Do they run with the same result?

Important note: don't have access to crontab/SSH

quantme
  • 3,609
  • 4
  • 34
  • 49
  • Please forgive if the title is not really clear but I don't know how to entitle it (could be a long one) – quantme Jan 25 '21 at 21:30
  • 1
    If you are trying to run a shell/bash from within another shell/bash -- simply use `sh /var/www/yourfile.sh` or `bash /var/www/yourfile.sh` -- It will fork the commend inside your script into child processes. Simple enough if I understand your question correctly .. – Zak Jan 25 '21 at 21:39
  • What's gong to throw people off .. Is that `--cron --home` are not "standard" flags, so what you are trying to accomplish might need some more explanation / clarification. – Zak Jan 25 '21 at 21:43
  • @Zak don't know a thing about cron but `--cron --home` are parameters from the `acme.sh` [script](https://github.com/acmesh-official/acme.sh#2-or-install-from-git) – quantme Jan 25 '21 at 22:10
  • Looks like the redirection `>` isn't allowed. So put that line in a script and simply call that. –  Jan 26 '21 at 00:01

1 Answers1

1

I believe you want option 1, because you want to run the acme.sh script.

Option 2 and option 3 are essentially equivalent in bash, because source is an alias to . in bash. However, they are not equivalent in sh, because . exists in sh but source does not (this is because source a non-POSIX bash extension).

When source or . are used, this is similar to using :load in Haskell's GHCi or Scala's REPL, or load in Lisp or Clojure. The source or . commands tell the shell to read, parse, and evaluate code written in a separate source file in the context of the current shell. Essentially, it allows functions and variables defined in a separate file to be made available in the context of the "calling" shell script.

What option 1 will do is run the acme.sh. You want this option because you don't want the acme.sh script to be run in your current shell (you might have some aliases or functions already defined in your current shell that could cause naming collisions). Running bash acme.sh is similar to running python my_code.py: the bash interpreter will execute the contents of acme.sh.

For more info on source and ., see:

Shane Bishop
  • 3,905
  • 4
  • 17
  • 47