sudo命令后如何执行多个命令 [英] how to execute multiple commands after sudo command

查看:1280
本文介绍了sudo命令后如何执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行批处理才能登录到服务器,进入sudo su - username并运行特定命令.

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

我尝试了以下代码:

putty username@servername -pw password -m myshell.sh

myshell.sh:

myshell.sh:

#!/bin/sh
sudo su - username
cd to particular folder
then tail a file

我进入sudo,但此后脚本卡住,直到我注销.

i am getting in sudo, but after that the script stucks until i logout.

推荐答案

您可以使用sh -c,然后在命令之间使用分号,不过我会考虑注释中建议的解决方案,只是将整个脚本作为sudo运行.

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

这篇关于sudo命令后如何执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆