Sudo visudo problem

Hello,
I’m not sure if it’s the nature of this forum to answer this type of question, but my distrib is KDE Neon and not Kubuntu, so I’ll start here instead :slight_smile:

I use Neon stable, I have written a script to backup my personal data using “mount”, “umount”, and rsync. The script is supposed to run when I start my PC. The problem is that all of these commands have to be run as a superuser and even though I modified the /etc/sudoers.tmp and successfully checked if the /etc/sudoers was modified, the script doesn’t go through… I added the script itself to sudoers.tmp as follows:
laurent ALL=(ALL) NOPASSWD: /home/laurent/Documents/Informatique/scripts/Sauvegarde_Auto.sh
Then I added the first command of the script with “mount” (I also tried with sudo before “mount”):
mount /dev/disk/by-uuid/df46955c-0503-41fc-a73e-ce3b28911395 /media/
Nothing is working out… I set up a log:

++ date +%A

  • jour=Wednesday
  • ‘[’ Wednesday = Wednesday ‘]’
  • kdialog --yesno ‘Voulez vous faire une sauvegarde?’
    ++ echo 0
  • Verif=0
  • ‘[’ 0 = 0 ‘]’
  • lsusb
  • grep -e ‘ID 0480:a00c’
    Bus 002 Device 002: ID 0480:a00c Toshiba America Inc External USB 3.0
  • mount /dev/disk/by-uuid/df46955c-0503-41fc-a73e-ce3b28911395 /media/
    mount: /media: must be superuser to use mount.

I’m going to provide the entire script :

#!/bin/bash
set -e
set -u
set -x
sleep 10s
exec &> /home/laurent/Sauvegarde_Auto.log

jour=$(date +%A)

if [ "$jour" = "Wednesday" ]
then
    kdialog --yesno "Voulez vous faire une sauvegarde?"
    Verif=$(echo "$?")
    if [ "$Verif" = "0" ]
    then
        if lsusb | grep -e "ID 0480:a00c"
        then
            mount /dev/disk/by-uuid/df46955c-0503-41fc-a73e-ce3b28911395 /media/
            rsync -avrz --exclude=".*"  /home/laurent/ /media/laurent/ > ~/sortieRsync && kdialog --textbox ~/sortieRsync
            rm ~/sortieRsync #&& rm /media/laurent/sortieRsync
            kdialog --msgbox "Sauvegarde terminée."
            sudo umount /dev/disk/by-uuid/df46955c-0503-41fc-a73e-ce3b28911395
            exit
        else
            while ! lsusb | grep -e "ID 0480:a00c"
            do
                kdialog --yesno "Le périphérique n'a pu être monté. Vérifier s'il est branché."
                Verif=$(echo "$?")
                [ "$Verif" = "0" ]
                if [ "$Verif" = "1" ]
                then 
                    break
                fi
            done
            mount /dev/disk/by-uuid/df46955c-0503-41fc-a73e-ce3b28911395 /media/
            rsync -avrz --exclude=".*"  /home/laurent/ /media/laurent/ > ~/sortieRsync && kdialog --textbox ~/sortieRsync
            rm ~/sortieRsync #&& rm /media/laurent/sortieRsync
            kdialog --msgbox "Sauvegarde terminée."
            umount /dev/disk/by-uuid/df46955c-0503-41fc-a73e-ce3b28911395
            exit 0
        fi
    else
        exit 0
    fi
else
    exit 0
fi

This script was working fine under Debian12, but I switched on Neon a few weeks ago.
If somebody has a solution, please let me know.
Thank you! :slight_smile:

  • both mount and umount in your script should require sudo

  • IMHO it would be better to allow just mount and umount without password for your user in the sudoers file, not the script itself

  • I would also suggest to mount your backup disk to a subdirectory of /media, not /media itself (e.g. to /media/my_backup_disk) - in case the system wants to mount something else to e.g. /media/$USER

PS: If you wanted to use a graphical backup program you could use e.g.

Thanks for your answer, unfortunately I’m going to run out of time for today and the 3 next ones. I didn’t know " Plasma’s integrated backup funtionality ( → System SettingsPersonalisationBackups )". I have to see what I can do with it. The thing with my script is that I can let my external DD plugged in all the time, it is just mounted for the update then umounted and sleep the rest of the week… I’ll see all of it later.

Thank you so much!