是否有可能以管理员权限或以特定用户身份执行Perl脚本? [英] is it possible execute a perl script with admin rights or as a specific user?

查看:140
本文介绍了是否有可能以管理员权限或以特定用户身份执行Perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个perl脚本,在该脚本中,我必须关闭mssql服务器,执行一些操作,然后重新启动它。我知道一种方法是使用netstat停止服务,但我无法用那个。因此,我尝试安装DBI和DBD :: ODBC模块。
更多信息,请参见:从perl脚本DBI关闭MSSQL服务器
,但是当我尝试使用此命令关闭服务器

I'm writing a perl script in which I've to shutdown my mssql server ,do some operation and then I've to restart it.I know 1 way is to use netstat to stopt the service but I cann't use that. So I tried installing DBI and DBD::ODBC module. More info here :Shutdown MSSQL server from perl script DBI But when I trying to shutdown my server using this command

$dbh->prepare("SHUTDOWN WITH NOWAIT ");

对我不起作用:
我得到了社区的答复

It's not working for me : I got this response from the community


SHUTDOWN权限已分配给 sysadmin和serveradmin 固定服务器角色的成员,并且它们不可转让。我认为与Perl一起使用此权限不同(希望如此)。

SHUTDOWN permissions are assigned to members of the sysadmin and serveradmin fixed server roles, and they are not transferable. I'd consider it unlike(hopefully) that perl is run with this rights.

所以请告诉我是否有一种运行方法上面的命令作为这些用户?或除此外我还有什么办法。请注意,我有一个约束,我不能简单地将其作为Windows服务停止。

So please tell me is there a way to run the above command as these users ? or what can I do other than this . Note that I have a constraint tha tI cann't simply stop it as windows service.

推荐答案

如果脚本是通过a执行的Web浏览器,然后由Web服务器定义执行脚本的用户。摆弄这个用户可能不是一个好主意。

If the scripts are executed through a web browser then the user executing the scripts will be defined by the web server. It will probably not be a good idea to fiddle with this user. Just leave things as they are.

您可以做的是创建一个由特权用户与CRON一致地运行的Perl脚本。

What you can do is to create a Perl script that is being run by a privileged user on a consistent basis with CRON.

由CRON运行的脚本可以检查特定内容,例如由脚本编写的文件,其中执行脚本的用户具有较少的特权。

This script being run by CRON can check for specific content like a file which has been written by a script where the user executing the script has lesser privileges.

因此它的工作方式如下:

So the way it could work is as follows:


  1. 您执行浏览器。 cgi通过浏览器执行特定任务。

  1. You execute browser.cgi through a browser to do a specific task.

browser.cgi将指令写入文件。

browser.cgi writes instructions to a file.

每1分钟priveleged.cgi通过CRON执行一次。 (root用户可以执行priveleged.cgi)。

Every 1 minute priveleged.cgi executes via CRON. (The root user could execute priveleged.cgi)

priveleged.cgi读取文件browser.cgi编写了指令,并根据指令启动和停止服务。

priveleged.cgi reads the file browser.cgi has written for instructions and starts and stops services according to the instructions.

这篇关于是否有可能以管理员权限或以特定用户身份执行Perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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