来自cronjob的python脚本给出错误,但不是来自bash。(python script from cronjob giving error,but not from bash.?)

编程入门 行业动态 更新时间:2024-10-13 12:20:29
来自cronjob的python脚本给出错误,但不是来自bash。(python script from cronjob giving error,but not from bash.?)

我试图通过子进程python模块从cronjob运行nessus扫描。 ,但是从cronjob来看它是错误的。 但是从bash执行脚本时没有出现任何错误?

cronjob代码

01 11 * * * /root/nessusscan.py

和脚本中的子进程调用是

subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res'])

从bash它工作正常,但从cronjob我收到邮件中的跟随错误

Traceback (most recent call last): File "/root/nessusscan.py", line 9, in <module> subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res']) File "/usr/lib/python2.7/subprocess.py", line 493, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 13] Permission denied

I am trying to run a nessus scan from cronjob by subprocess python module. ,but from cronjob it's is giving an error. But not giving any error on execution of script from bash?

the cronjob code

01 11 * * * /root/nessusscan.py

and subprocess call in script is

subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res'])

from bash it's working fine but from cronjob i am getting following error in mail

Traceback (most recent call last): File "/root/nessusscan.py", line 9, in <module> subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res']) File "/usr/lib/python2.7/subprocess.py", line 493, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 13] Permission denied

最满意答案

我想回答一个问题,我会回答我自己的问题。 这样他们也可以摆脱这个错误。 在我的情况下,通过给出nessus的路径"/opt/nessus/bin/nessus"来解决错误

用"/opt/nessus/bin/nessus"代替nessus

cronjob无法获得nessus命令的路径。它现在正在工作。

Thnx to evry one i am answering my own question for other people who will vist this thread. So that they can also get out of this error. In my case error got solved by giving the path of nessus which is "/opt/nessus/bin/nessus"

replaced nessus with "/opt/nessus/bin/nessus"

cronjob was not able to get the path of nessus command.It's working now.

更多推荐

本文发布于:2023-08-02 07:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   错误   python   cronjob   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!