there's a script that I have and it needs to be run by root user. I just wanted to know how to run that script using su
in the script. - I'm running CentOS7.
The command I attempted (below) failed:
su root credentials=/home/root/root.cred
and then continue with the rest of the script - sadly it didn't work. I included the .cred file because root asks for the root password when changing to root. Is there a way to run su root
and change to root in a script.
Any ideas?
I may be getting confused but I just want to explain further:
I have a script that I want to be able to run from a regular (non sudoer) user, but this command is a sudo command - therefore only executable by a sudoer. Root is a sudoer, so when the script is run by the regular user - it will run as root in the script. If I begin the script with su root
it can't get past that because it requires a password. Is there a way to enter the root password to get past the su
command and into running the rest of the script using the script itself. Maybe echo
or something? - I have no idea, this is why I am making this question.
Any futher questions, just ask me below :)