This question already has an answer here:
I created a user named shut so that whenever one logs in using that username the machine would shut down. For that I placed the below command in the end of the .profile.
exec sudo shutdown -h now
But this didn't serve the purpose. When the user shut logs in, rather than the machine shutting down, the login screen is coming back. So the user isn't able to log in but at the same time getting back the same login screen.
The reason I feel is that because password for the user shut isn't provided , the machine isn't shutting down. And because of exec, the login screen is coming back (which is fine).
Now to solve my work, I need a way so that it would automatically take my password when the above sudo command executes. I checked
man sudo and I think
-A option has to be used.
Following that man page, I ran
SUDO_ASKPASS=/home/ravbholua/pass.txt export SUDO_ASKPASS
Then to check whether it's working, I ran
ravbholua@ravbholua-Aspire-5315:~$ sudo -A pwd sudo: unable to run /home/ravbholua/pass.txt: Permission denied
From this output, it means this path file has to run and provide my password as output to sudo. What earlier I thought, it would take the password from this file named pass.txt, so I entered my password in this file. But no!!!!!!!
Any suggestions please!