How to execute the command after sudo su


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.

Any idea.

Thanks in advanced.


The 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.


<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:


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>



  • VBScript hangs when launching batch file with WShell.Script Run
  • Stop a find-in-file search in Visual Studio 2013 which is taking forever
  • How do you download a image/png data URI in Edge?
  • Styling text for textarea Wicket
  • Singleton Alternative - is it equivalent?
  • Excel VBA Intersect
  • why does .next() give me 'undefined'
  • How to get the index of element in the List in c#
  • In Akka, is ActorContext thread safe?
  • How to use the resource module to measure the running time of a function?
  • how to set to NULL all the filestream varbinary(max) fields?
  • Why doesnt this Java loop in a thread work?
  • (Tcl/Expect) clear screen after exit
  • Scanner nextInt() and hasNextInt() problems
  • jQuery: How to AJAXify WordPress Search?
  • Passing “get” parameters doesn't work, parameter not visible in the link
  • Trying to get the char code of ENTER key
  • Authentication in Play! and RestEasy
  • How to assign byte[] as a pointer in C#
  • Code in Job's Script Block after Start-Process Does not Execute
  • Stop Bash Script if Hive Fails
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Do I need to reset a Perl hash index?
  • MongoError: Incorrect arguments
  • Django rest serializer Breaks when data exists
  • Read text file and split every line in MSBuild
  • C# - Serializing and deserializing static member
  • Java applet as stand-alone Windows application?
  • javascript inside java/jsp code
  • Sending data from AppleScript to FileMaker records
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • Error creating VM instance in Google Compute Engine
  • need help with bizarre java.net.HttpURLConnection behavior
  • Authorize attributes not working in MVC 4
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal