• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Run cron task command with arguments

eliamarsura

Basic Pleskian
Hi
I create a script with bash that's need some arguments

I try to schedule this on plesk panel but it is executed without arguments.

The command look like this:
bash /root/myscript.sh argument1 argument2 argument3

If I execute the script from shell everything work fine (argument1 become $1 and so on), but if I put this inside Scheduled Tasks (Cron jobs) in plesk it doesn't read the arguments.
 

Attachments

  • Immagine 2022-02-21 234640.jpg
    Immagine 2022-02-21 234640.jpg
    25.2 KB · Views: 23
If I am not mistaken you don't have to prepend the command with bash. Just /root/myscript.sh argument1 argument2 argument3 should work.
 
Sorry to hear it didn't work. Did you try to output the results of the cronjob to a log file for debugging/analysis purposes?
 
Sorry, I meant that you output the content of your script to a file to log for your own debugging purposes.

I've created a quick bash script for testing. For me using arguments in the cronjob seem to work fine.

Bash:
#!/bin/bash
# Set script permission: chmod +x argument.test.sh

echo "Argument: "${1}

My cronjob settings look like this:
Schermafbeelding 2022-02-22 om 21.21.27.png

This outputs: Argument: hello
 
Last edited:
Finally I found the solution!
The problem wasn't the arguments but the plesk command

I had to use
/usr/sbin/plesk ext sslit --certificate -issue -domain $1 -registrationEmail $2 -secure-domain -secure-mail -secure-webmail -wildcard

instead of
plesk bin ext sslit --certificate -issue -domain $1 -registrationEmail $2 -secure-domain -secure-mail -secure-webmail -wildcard

If I use "plesk bin" directly on command line it's work, but it doesn't work if I pass trough cronjob
 
Back
Top