how to execute multiple commands after sudo command

后端 未结 2 996
情书的邮戳
情书的邮戳 2021-01-14 02:11

I need to run a batch to login to server, get in sudo su - username and run specific commands.

I tried below code:

putty username@server         


        
相关标签:
2条回答
  • 2021-01-14 02:51

    You can use sh -c and then use semicolons between commands, I'd consider the solution suggested in the comments though, just have whole script run as sudo.

    sudo sh -c "cd /tmp;pwd;cd /dev;pwd""
    
    0 讨论(0)
  • 2021-01-14 03:01

    updated my shell file with below command and it worked:

    #!/bin/sh
    sudo su - username << block
    cd /; 
    tail filename;
    block
    

    all the commands are to be written in block and separated by ";"

    0 讨论(0)
提交回复
热议问题