How can I automate MX Snapshot from cron without entering a sudo password?
Asked by
BlueMango47
I use MX Linux for professional systems that need regular backups. I'd like to create a Bash script that runs MX Snapshot automatically on a schedule and produces a live, bootable USB drive without requiring me to enter a sudo password each time. I'm not experienced with scripting, so I'm looking for guidance on whether this is possible and how to set it up safely.
Answers
A cron job can launch a Bash script at the desired interval, but creating a bootable USB involves more than just copying files and may require a target device that is always connected and identified reliably. Make sure the script checks the correct destination before writing, since using the wrong device path could erase another disk. Youโll also need to decide how to handle logs, failures, and whether the USB should be unmounted safely when the job finishes.
Reply to this answer
Yes, this is possible, but the snapshot operation needs root privileges. The safer approach is usually to run the scheduled job as root rather than placing a broad password-free sudo rule in your account. If sudo must be used, create a narrowly scoped rule in a file under /etc/sudoers.d/ that permits only the specific snapshot command with NOPASSWD. Test the command manually first, then account for cronโs limited environment and use absolute paths in the script.
BlueMango47: Thanks for explaining. Iโm not a techie and canโt write the script myself, so I was hoping for an example or a reference showing how to build it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
BlueMango47: Iโd appreciate a tutorial or library reference for scripting this, especially since I donโt have enough coding experience to start from scratch.