我想编写一个bash脚本,以普通用户身份login时在root下执行一些任务。 有没有可能有这样的事情?
#!/usr/bash sudo -i <multiple line perform all my sudo command> ... ... ... exit <back to my user command, continue some other task>
当然,我可以每行都写一个sudo,但是我想知道是否可以做类似上面的事情? 谢谢。
怎么样这样简单的东西。
#!/usr/bash sudo bash << EOF # Everything until EOF is run in a sub-shell echo 'Hello World' whoami EOF
这是一个更简单的方法:
#!/usr/bash sudo sh another_script.sh <continue some other task>
这是另一个脚本。
#!/usr/bash <multiple line perform all my sudo command> ... ... ...
如果你想避免用sudo
前缀每个命令,你可以将它们包含在另一个脚本中并调用它。