0

I tried to execute the multiple commands in a single line using &&, but it isn't working in the following case. It just executes the first sudo command alone.

sudo /usr/bin/rootsh -i -u ditest && Set_proj && 1

Note: Only the first one is Sudo command and the remaining are a normal ones. I already tried using the following command. But it doesn't works

sudo /usr/bin/rootsh -i -u 'ditest && Set_proj && 1' 

Multiple command doesn't works even though if I enter "Set_Proj && 1" after executing the first command. Only the first command is executed (Set_proj).

In other cases multiline commands are working fine. Eg: cd jtest && ls

Edited: Its not a duplicate of how to run two commands in sudo?. I described clearly that I haven't used multiple sudo commands. Once logged into putty, the command sequence will be

jacob:/home/users/jacob: sudo /usr/bin/rootsh -i -u ditest  
[ditest] ditest> Set_Proj    ***List of projectes displayed*** 
> 1     ***Select any project***
Community
  • 1
  • 1
Testers Logic
  • 79
  • 1
  • 7

2 Answers2

0

simple. Put one sudo by command:

sudo apt-get update && sudo apt-get dist-upgrade -y

Usually, only the first sudo ask for password, andit cached for next sudos

FOP
  • 962
  • 1
  • 10
  • 21
0

Use bash -c, like this

sudo bash -c "ditest && Set_proj && 1"

If you want to run sudo as another user then,

sudo -H -u user bash -c "ditest && Set_proj && 1"
Syscall
  • 19,327
  • 10
  • 37
  • 52
sung sung
  • 21
  • 1