I have some scripts for backing up data. Some of them need root access, so I use them with
sudo. However, sometimes I get confused, e.g. for the mySQL backup, which also needs a mySQL root password.
I have now implemented a workaround in a bash script like this
echo "Please enter root password" sudo echo "Ok" sudo mysqldump --all-databases --opt -u root -p > ~/backup.dump
The idea behind this is: the sudo password will be cached. If it is entered in the beginning, it will not be prompted during the mySQL backup, so it cannot be confused with the mySQL root password any more.
Is this approach safe to use or is there anything wrong with it?