I use MX Linux for professional systems that need regular backups. I would like to create a Bash script that runs MX Snapshot on a schedule and produces a bootable USB or live image automatically through cron. The job should run unattended without prompting for my sudo password. Is this possible, and what is the safest way to configure it? I'm not experienced with Bash scripting, so guidance on the script structure and required permissions would be helpful.
2 Answers
Yes, it’s possible, but the scheduled task will need the privileges required by MX Snapshot. The usual approaches are to run the cron job as root, or allow one specific snapshot command to run without a password through a narrowly scoped file in /etc/sudoers.d/. Avoid disabling the password requirement for all sudo commands. Also make sure the destination device is identified reliably, because writing to the wrong USB drive could erase data. Start by running the snapshot command manually, then place that tested command in a script with logging and error checking before scheduling it.
A safer setup is to create a root-owned script that calls the official MX Snapshot command with explicit options for the output location, then schedule it from root’s crontab. Keep the script and its directory writable only by root, verify that the USB drive is mounted consistently, and test the job with a harmless output before allowing it to overwrite removable media. Cron has a limited environment, so use absolute paths and write output to a log file. The exact command-line options depend on the MX Snapshot version installed, so check its built-in help or documentation rather than guessing the arguments.

I’m not comfortable writing Bash either. The important part is to first find the exact command that successfully creates the snapshot when run interactively. Once that works, the scheduling and permissions can be added around it; otherwise cron troubleshooting becomes much harder.