I have a test script (well it just the very first part of the script i want to use)
❱cat bash/btrfs-to-sda-backup.sh
#!/bin/bash
# Variables
SNAPSHOT_DIR="/mnt/snapshots"
BACKUP_MOUNT="/mnt/target"
BACKUP_SNAPSHOTS="$BACKUP_MOUNT/snapshots"
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
# Check if the backup mount point is already mounted
if ! /usr/bin/mountpoint -q "$BACKUP_MOUNT"; then
echo "$BACKUP_MOUNT is not mounted. Mounting now..."
/usr/bin/mount /dev/sda3 "$BACKUP_MOUNT"
else
echo "$BACKUP_MOUNT is already mounted."
fi
/usr/bin/umount "$BACKUP_MOUNT"
exit
I have adjusted visudo:
❱sudo -l
Matching Defaults entries for greg on greg-optiplex7050:
timestamp_timeout=120
User greg may run the following commands on greg-optiplex7050:
(ALL) NOPASSWD: /home/greg/bash/btrfs-to-sda-backup.sh
(ALL) ALL
It runs fine manually
❱sudo /home/greg/bash/btrfs-to-sda-backup.sh
/mnt/target is not mounted. Mounting now...
❱cat btrfs-backup.log
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
Iv had chatGPT4o running around in circles on this, i think i pissed it off ^^
I cant figure why it keeps asking for a password and wont run?
Why do you adding a script to a normal users crontab if it needs to be executed with elevated permissions? Why not adding this script to roots personal crontab? No sudo required to run it.
hmm, well i never thought of that. iv always done it this way.
I was going to use vorta to execute the script after it had finished its backups to the NAS by just adding the script to it’s “Post-backup” shell command option. Ii really dont want to involve cron at all.
I suppose i could do it via root crontab. But why wont this work, its works like this before?
Did it really worked before? I never used cron in recent years, but I don’t remember that something like this worked. I always started the script as a normal user and added the sudo command in front the programs that need elevated permissions. Of course this would mean you need to add /usr/bin/mount and the umount command to sudoers wit NOPASSWD. But adding such a important command to it, might be considered a security risk.
Don’t ask ChatGPT - it doesn’t “know” squat - just repeats what gets repeated on the interwebs.
(and is woke biased, too … which is “good to know” IMO, but not important here)
I can’t believe that you have always done it this way - since it obviously asks for a password and this would never have been different before.
Probably along the same lines and definable as per the previous statement.
Its a bit amusing the word is so misused and misunderstood.
Not because its ironic - quite the contrary. See the term had a history of use in hiphop and similar communities well before it entered mainstream consciousness. It wasnt necessarily political either.
It largely stood as an antonym for asleep, ie: ignorant. Like “dont sleep, read a book, get woke”.
The fact that its somehow gained notoriety while still being widely confused … is just so perfect for slang of any flavor. “Are you kids hitting the mary jane cigarettes?”. But extra so for this particular term as it is supposed to be the opposite of uninformed.
Thx, I have used systemd timers before but i just wanted to put the execution under vortas control.
It just seems better to me to have all the backup timings in one place.
It works from roots crontab, and im sure it would work from systemd. I find systemd a massive headache especially to just fire a single script once every few hours, massive overkill and head scratching.
But is there not a way to do it from my under my user then? I know i have done it before. If not i shall just leave it in roots cron.
You can work around this by creating two more units.
mount unit - define the mountpoint (do no enable)
automount unit - mount when mountpoint is accessed
This will simplify your script - remove the mount check - just access the path with the script - mounting is done by the automount and is unmounted again after predefined idle time.