I have the root password in one of my scripts and I want to launch another script which requires root permission from this script. How can I use the root password which I have so that I do not have to ask the user the root password which launching 2nd script.
There's a lot of security implications in this, but let's get right to the best way to handle this.
Don't use the root password directly. Use sudo to run the scripts. Sudo is installed by default on Ubuntu and is available on almost all popular Linux distributions in the package repositories. Once sudo is installed, you'll want to edit /etc/sudoers.
But do your scripts absolutely have to run as root? Most times this isn't required at all, but is done out of convenience.
Another option would be to set suid on the file to root. Example:
Just for your own knowledge if you don't want to set sudo to run without a password you can pass the password to sudo through stndin like
However this can be a security concern as it will show the password in history or anyone watching like "ps". You can also look into Expect and Empty.