linux下在root用户登陆状态下,以指定用户运行脚本程序实现方式

当前ssh登陆linux的是root用户

但是应用程序必须以webmaster用户运行,否则报错

那么实现方式如下:

#!/bin/sh
user="webmaster"
if [ `whoami` != "${user}" ]; then
        exec su - "${user}" -c "sh /mnt/checkP1.sh"
fi

echo "Agoly"
id
whoami

while true
do
        pnmon=`ps aux | grep nmon | grep -v grep`;

        if [ "$pnmon" == "" ]; then
                sleep 1;
                echo "no nmon process";
                echo "正在启动中";
                nmon -f -s3 -c300 -m /mnt;
        else
                echo "process exsits";
                break;
        fi
done

posted @ 2017-03-16 12:24  Agoly  阅读(3501)  评论(0编辑  收藏  举报