I need to execute "monit restart haproxy" command after sudo su.
This is my script.sh
sudo su monit restart haproxy.
Here if i will execute the script.sh file then it will hang and it is not executing the monit restart haproxy command.
Thanks in advanced.Answer1:
sudo command is expecting you to enter a password which is why it will hang, you can use a pipe so that the password is passed to the command like this:
echo <password> | sudo su monit restart haproxy.Answer2:
<a href="https://askubuntu.com/questions/376199/sudo-su-vs-sudo-i-vs-sudo-bin-bash-when-does-it-matter-which-is-used" rel="nofollow">Here</a> comes some information about sudo su. You need to enter password for sudo or su command, here is some quote from link i posted that may be the source of your problem:<blockquote>
sudo - sudo is meant to run a single command with root privileges. But unlike su it prompts you for the password of the current user. This user must be in the sudoers file (or a group that is in the sudoers file). <strong>By default, Ubuntu "remembers" your password for 15 minutes, so that you don't have to type your password every time.</strong></blockquote>