简体   繁体   English

如何从另一个用户的另一个Shell脚本中调用Shell脚本?

[英]How to call shell script from another shell script from another user?

How to call shell script from another shell script from another user? 如何从另一个用户的另一个Shell脚本中调用Shell脚本?

Can you please share the sample code? 您能否分享示例代码?

I have two scripts: 我有两个脚本:

showdate.sh: showdate.sh:

#! /bin/bash
echo "Date is : `date`"

and mainscript.sh: 和mainscript.sh:

 #! /bin/bash
 su - nmsadm 
 echo " You are logged in as `whoami`"
 echo "`./showdate.sh`"

When I am executing mainscript I want to switch to other user and run showdate script. 执行主脚本时,我想切换到其他用户并运行showdate脚本。

Here is the output 这是输出

#./mainscript.sh    
You have new mail.
-bash-3.2$

It switches to nmsadm user but does not execute show script. 它切换到nmsadm用户,但不执行show脚本。

To call the script as another user, use the following syntax: 要以另一个用户身份调用脚本,请使用以下语法:

sudo -u nsadm ./showdate.sh

Make sure the showdate script is executable 确保showdate脚本是可执行的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM