-2

When i run a certain command written in aa.sh bash file through aa.sh and then command terminal ask for password to continue execution like sudo password or git remote password to authenticate.

My Question is "how to give a password automatically in .sh file which i stored in variable when it asking to enter and then i assign that variable to continue execution".

Harat
  • 127

1 Answers1

1

Well for sudo password you can simply execute the script with sudo prefix and it will ask for password and it will not ask for password for any sudo commands within the file.

Update

If you want to specify password for authentication to some application like mysql, git etc. Then you have to follow the proper syntax for that specific application. Eg: to take backup of mysql database through bash file. you can use the following command

mysqldump -u root -p "YOUR_SECRET_PASS" "DB_NAME"

Similarly for git you need to find out how it takes the password non interactively. Therefore the syntax to specify password will varies application to application. Consider the following solution in case of git. This will save credentials once it for all.

git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git
  • i gave example of sudo, but the scenario is, how to automatically fill password when password require to continue executing command – Harat Sep 05 '19 at 11:42
  • yes, you are right. I need this kind of functionality for git – Harat Sep 05 '19 at 12:24