Scheduled Jobs don't run my script with VirtualMin API commands ??!

Some command from the VirtualMin API doesn’t seem to work when my script is launch by a ‘Scheduled Cron Jobs’… any idea ?

My script is working perfectly if I launch it from :

  • ssh command, as root, like : sh /home/d7/myscript.sh
  • in the WebMin > Scheduled Cron Jobs, when I "Run" manually.
Don't work completely when I scheduled it, via 'Scheduled Cron Jobs' option. In fact, all my command with VirtualMin API are skipped !

Here my code

#!/bin/sh

#iterate on servers
virtualmin list-domains --name-only --toplevel --enabled | while read domain; do

    # To action ... 
    echo ${domain}

done

#send report

var_date=date +%m-%d-%Y
MAILFROM="support@example.com"
MAILTO="support@example.com"
SUBJECT=“Report - $var_date”

Send the email

cat - ${data_dir}/Report.txt <<EOF | /usr/sbin/sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
EOF

Via the scheduled job, I just received email after few second. But the script should run about 40 min before to complete and send this mail.

Any idea ? Permissions errors ? Can’t run VirtualMin API command via Jobs ? … thanks :wink:

Just re try one hour without success, same behavior : don’t want to run from a Scheduled Jobs… :frowning:

#!/bin/bash mail -s "drush report start" me@example.com virtualmin list-domains --name-only --toplevel --enabled | while read domain; do mail -s "drush report ${domain}" me@example.com done mail -s "drush report end" me@example.com

Via a Scheduled Job, I received the 1srt and the 3rd email, not the 2nd… why ?

Howdy,

Hmm, it’s hard to say why that’s not working – code run from cron jobs can be fickle sometimes :slight_smile:

If it works from the command line, it means that your syntax should be correct.

The environment path within a cron job can sometimes be different – you might want to try using the full path to commands (such as /usr/bin/mail, rather than just “mail” – and same with the “virtualmin” command).

If that doesn’t help, you may want to have it generate some debugging output to help identify what the issue is.

-Eric

Thanks!!!

It’s working now with the full path of the commands. Additionally I discover these commands : “which” and “logger”… which help a lot :wink:

Here my code :
domains=$(/usr/sbin/virtualmin list-domains --name-only --toplevel --enabled)
for domain in ${domains}; do

#to action…

done

Have fun ! Thank again.