I am running a shell script it asks for username and password to stop some service, I need to write some script that it will read username and password from my shell script and then sucessfully stop services without prompting username/password query.
You can create a script for stopping and starting instances. You can provide sudo access to the user which don't have access to stop/start services, there you can give nopassword authority to user and by this way script shouldn't ask you username and password then.
It is never recommended to hardcode a password in a script.
Let me give you an example here.
Lets say you are using a user named user1 and services are owned by user user2. So create script for simple stopping and starting services and make owner as user2 (Note: if you don't have permissions for that you can contact root for same).
Then root can give you access for
sudo
with non password option there. This means you will be able to run script with user1 (Which actually don't have access to STOP and START services directly) but this
sudo
access will give user1 ability to do so.
kindly let me know if I can help you further on same.
When i run below script script it ask me username and password.
./stop-service.sh
That password not belong to any application, it is database password which i need to put in some script so it will not prompt me for username/password and stop service with script.
It is not operating system password, i am telling you, it is database username and password which i need to provide in script so it will not ask me password, it is not related with sudo or any other operating system level thing, it is asking for two arguments username/password which i need to put in script so my service got stop automatically.
---------- Post updated at 03:18 AM ---------- Previous update was at 03:17 AM ----------
Please check my above script i clearly mentioned that example in detail for my script.
You really don't understand my query, i am stopping application that requires to stop some services, for that it is asking for database username/password, database username/password is not present in /etc/passwd it is basically stored in database.
so when i run stop-script.sh it ask me to provide username/password, which i want to put in my script, but don't understand the logic of it. Please it is not operating system /etc/passwd question. This question is related with shell scripting.
How is it not working properly? Is it printing any diagnostic messages? Does it return a prompt for the next command? (If so, what is the exit code from this script?)
stopservice.sh is big file have alot of thing with java and database. Thanks now it is working, my mistake i specify wrong password, rest everything is same.