# Script to push SSL certs to other devices on renewal?

**URL:** <https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939>\
**Category:** Help! (Home for newbies)\
**Created:** [June 25, 2025, 9:03pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939 "2025-06-25T21:03:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GJSchaller](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/gjschaller/32/8901_2.png) [@GJSchaller](https://forum.virtualmin.com/u/GJSchaller)\
**Post date:** [June 25, 2025, 9:03pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/1 "2025-06-25T21:03:05Z")

</div>

| SYSTEM INFORMATION | |
| --- | --- |
| OS type and version | Debian Linux 12 |
| Virtualmin version | 7.30.8 Pro |

I am using a wildcard cert for my main domain on several other devices in my home, such that when my Virtualmin server updates the cert via LetsEncrypt, it calls a script to run two sub-scripts, which each target a specific device.

The script I have in Virtualmin is:

```auto
#!/bin/sh
if ["$VIRTUALSERVER_ACTION" = "SSL_DOMAIN"]; then
    if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
        /root/scripts/deploy-freenas/deploy_freenas.py
        /root/scripts/pihole-certs.sh
    fi
fi

```

I know the two sub-scripts it calls work when I run them individually, and the main script (above) works when I comment out the “if” statements and run it manually.

It looks like I’m having trouble with properly triggering the script on SSL Renewal - can I get verification my script is correct?

---

<div class="post-metadata">

**Author:** ![Joe](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/joe/32/9_2.png) [@Joe](https://forum.virtualmin.com/u/Joe)\
**Post date:** [June 25, 2025, 9:15pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/2 "2025-06-25T21:15:01Z")

</div>

The script looks OK, to me.

I would suspect something is missing from the environment that makes your called scripts not work. Try checking the Webmin action log (in `/var/webmin/webmin.log`) and maybe adding some logging of your own to see what’s happening.

First make sure the `if` logic is sound:

```auto
#!/bin/sh
if ["$VIRTUALSERVER_ACTION" = "SSL_DOMAIN"]; then
    if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
        echo "We made it!" >> /root/cert-copy.log
        /root/scripts/deploy-freenas/deploy_freenas.py
        /root/scripts/pihole-certs.sh
    fi
fi

```

Then if that shows up in that file, redirect the output of those commands to the log (assuming they have output, if they don’t, add some). You need to just step through your assumptions, since one of them is wrong. I don’t think your logic related to when to run is wrong, but you should prove it before you start looking for what is wrong.

---

<div class="post-metadata">

**Author:** ![GJSchaller](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/gjschaller/32/8901_2.png) [@GJSchaller](https://forum.virtualmin.com/u/GJSchaller)\
**Post date:** [June 26, 2025, 12:28am UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/3 "2025-06-26T00:28:47Z")

</div>

This is my updated script, with testing calls:

```auto
#!/bin/sh
echo `date` " - Parent Script called successfully" >> /root/scripts/scriptlog.txt
if ["$VIRTUALSERVER_ACTION" = "SSL_DOMAIN"]; then
    if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
        echo `date` " - Parent script conditions met" >> /root/scripts/scriptlog.txt
        /root/scripts/deploy-freenas/deploy_freenas.py
        /root/scripts/pihole-certs.sh
    fi
fi
echo `date` " - Parent Script completed successfully" >> /root/scripts/scriptlog.txt

```

So it will log if it’s called by Virtualmin, and it will also log if the conditions are met, and when it ends (so I can see what’s between, if needed).

The pihole-certs.sh also logs to the same file, so there’s that. The deploy\_freenas.py is in Python which I’m not as familiar with, but hopefully if everything else runs, this one will to, and I can just check my TrueNAS to see if the cert updated.

Gonna wait a day before I renew my SSL Cert, so I’m not spamming the servers and lock myself out.

EDIT: I got a print statement to work in deploy\_freenas.py, so I can see exactly what’s being called when.

---

<div class="post-metadata">

**Author:** ![GJSchaller](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/gjschaller/32/8901_2.png) [@GJSchaller](https://forum.virtualmin.com/u/GJSchaller)\
**Post date:** [June 26, 2025, 12:52pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/4 "2025-06-26T12:52:59Z")

</div>

Before I did my test this morning, I added more output to the script to track where the failure is. The new script is:

```auto
#!/bin/sh
echo `date` " - Parent Script called successfully"
echo `date` " - Parent Script called successfully" >> /root/scripts/scriptlog.txt
if ["$VIRTUALSERVER_ACTION" = "SSL_DOMAIN"]; then
    echo "SSL Condition Passed" >> /root/scripts/scriptlog.txt
    if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
        echo "Domain Condition Passed" >> /root/scripts/scriptlog.txt
        /root/scripts/deploy-freenas/deploy_freenas.py
        /root/scripts/pihole-certs.sh
    fi
fi
echo `date` " - Parent Script ended successfully" >> /root/scripts/scriptlog.txt
echo "===" >> /root/scripts/scriptlog.txt

```

The output from renewing the cert in Virtualmin is:

```auto
Thu Jun 26 08:45:22 EDT 2025 - Parent Script called successfully
SSL Condition Passed
Thu Jun 26 08:45:22 EDT 2025 - Parent Script ended successfully
===

```

So it looks like the SSL part is working, it’s failing on recognizing [aiskon.net](http://aiskon.net) as the domain / server that the action is called on.

---

<div class="post-metadata">

**Author:** ![jimr1](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/jimr1/32/14173_2.png) [@jimr1](https://forum.virtualmin.com/u/jimr1)\
**Post date:** [June 26, 2025, 2:44pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/5 "2025-06-26T14:44:16Z")

</div>

Why not just echo  
`$VIRTUALSERVER_DOM`  
To see what it contains ? Perhaps echoing quotes around it to identify if the variable is empty

---

<div class="post-metadata">

**Author:** ![GJSchaller](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/gjschaller/32/8901_2.png) [@GJSchaller](https://forum.virtualmin.com/u/GJSchaller)\
**Post date:** [June 26, 2025, 3:20pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/6 "2025-06-26T15:20:22Z")

</div>

Good idea - Updated script:

```auto
#!/bin/sh
echo `date` " - Parent Script called successfully"
echo `date` " - Parent Script called successfully" >> /root/scripts/scriptlog.txt
if ["$VIRTUALSERVER_ACTION" = "SSL_DOMAIN"]; then
    echo "SSL Condition Passed" >> /root/scripts/scriptlog.txt
    echo "$VIRTUALSERVER_DOM" >> /root/scripts/scriptlog.txt
    if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
        echo "Domain Condition Passed" >> /root/scripts/scriptlog.txt
        /root/scripts/deploy-freenas/deploy_freenas.py
        /root/scripts/pihole-certs.sh
    fi
fi
echo `date` " - Parent Script ended successfully" >> /root/scripts/scriptlog.txt
echo "===" >> /root/scripts/scriptlog.txt

```

This is the output:

```auto
Thu Jun 26 11:17:21 EDT 2025 - Parent Script called successfully
SSL Condition Passed
aiskon.net
Thu Jun 26 11:17:21 EDT 2025 - Parent Script ended successfully
===

```

So it’s the right domain, but it’s not triggering the next part of the script, it seems.

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [June 26, 2025, 3:58pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/7 "2025-06-26T15:58:45Z")

</div>

> [@GJSchaller](#):
>
> `if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then`
> 
> > [@GJSchaller](#):
> >
> > So it’s the right domain, but it’s not triggering the next part of the script, it seems.

It needs spaces around [] to recognize it properly, i.e.:

```auto
if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
...

```

---

<div class="post-metadata">

**Author:** ![GJSchaller](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/gjschaller/32/8901_2.png) [@GJSchaller](https://forum.virtualmin.com/u/GJSchaller)\
**Post date:** [June 26, 2025, 4:32pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/8 "2025-06-26T16:32:44Z")

</div>

I had JUST noticed this when you posted - that fixed it!

```auto
Thu Jun 26 12:02:16 EDT 2025 - Parent Script called successfully
SSL Condition Passed
aiskon.net
Domain Condition Passed
deploy_frerenas called successfully.
Thu Jun 26 12:02:36 EDT 2025 - PiHole script called successfully
Thu Jun 26 12:02:36 EDT 2025 - Parent Script ended successfully

```

So the working script, without the troubleshooting code, is:

```auto
#!/bin/sh
if ["$VIRTUALSERVER_ACTION" = "SSL_DOMAIN"]; then
    if ["$VIRTUALSERVER_DOM" = "aiskon.net"]; then
        /root/scripts/deploy-freenas/deploy_freenas.py
        /root/scripts/pihole-certs.sh
    fi
fi

```

Thank you for the assist!

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [June 26, 2025, 7:01pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/9 "2025-06-26T19:01:11Z")

</div>

> [@GJSchaller](#):
>
> Thank you for the assist!

You’re welcome!

---

<div class="post-metadata">

**Author:** ![system](https://cdn.forum.virtualmin.com/uploads/default/original/2X/c/cd96d761e326db4b2bef94886a639109bd7a8e76.svg) [@system](https://forum.virtualmin.com/u/system)\
**Post date:** [July 4, 2025, 7:01pm UTC](https://forum.virtualmin.com/t/script-to-push-ssl-certs-to-other-devices-on-renewal/133939/10 "2025-07-04T19:01:33Z")

</div>

Closed on July 4, 2025, 7:01pm UTC

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.
