shell指令碼,指定使用者執行shell命令

2021-10-06 17:28:38 字數 532 閱讀 4802

系統環境:centos7

如root使用者下,實現用elk使用者啟動es,**如下:

#!/bin/bash

su - elk <<

eofecho "start elasticsearch..."

nohup sh /data/elasticsearch/bin/elasticsearch &

echo "start kibana..."

nohup sh /data/kibana/bin/kibana &

echo "es started"

eof

shell中,也可以用以下方法實現:

su - elk -c "pwd"
切換使用者只執行一條命令的可以用:su - user -c command

切換使用者執行乙個shell檔案可以用:su - user -s /bin/bash shell.sh

執行shell指令碼進入指定目錄

在linux環境下,常有通過shell指令碼進入指定目錄的操作,例如有一段指令碼chdir.sh plain view plain copy bin sh cd home user downloads pwd 在shell環境下通過.chdir.sh執行這段指令碼是無法進入downloads目錄的 ...

執行shell指令碼進入指定目錄

在linux環境下,常有通過shell指令碼進入指定目錄的操作,例如有一段指令碼chdir.sh plain view plain copy bin sh cd home user downloads pwd 在shell環境下通過.chdir.sh執行這段指令碼是無法進入downloads目錄的 ...

執行shell指令碼進入指定目錄

在linux環境下,常有通過shell指令碼進入指定目錄的操作,例如有一段指令碼 text.sh bin sh cd learn pwdls l在shell環境下通過.text.sh執行這段指令碼是無法進入learn目錄的 這是因為shell在執行指令碼時,會建立乙個子shell,並在子shell中...