Password in shell script for apps stop

Hi folks,

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.

Hello,

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.

Thanks,
R. Singh

Currently i am using below code. But it is not working properly.

stop-service.sh

USERNAME=username
PASS=pass123
./stopservice.sh << EOF
$USERNAME
$PASS
EOF

Hello,

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.

Thanks,
R. Singh

Dear

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.

Hello,

Here you can edit

edit /etc/sudoers 

and then you can give

username ALL=(ALL) NOPASSWD: ALL

there now if you will run the script it shouln't ask you password.

Same explaination is given in prvious post too.

Thanks,
R. Singh

Dear Sir,

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.

Hello,

It's not about O.S user or DB user, all users will be present in server. Could you please check

 cat /etc/passwd 

file and see if the same user is present there.

cat /etc/passwd | grep "Username"

Please check it and make your query clear then we can discuss on this further.

Note: you should have root access to see the file which I have mentioned above.

Thanks,
R. Singh

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?)

What is in the file stopservice.sh?

If you can�t touch the script stopservice.sh could be a job for expect Expect - Wikipedia, the free encyclopedia

It is giving me error, my script is correct or is there any mistake, it is not stopping service.

What error is it giving you?

And, I repeat, "What is in the file stopservice.sh?"

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.

Just confirming that my logic is correct or not?