@name 执行脚本内容 @param script_id 脚本ID @param script_body 脚本内容 @return dict
(self,script_id,script_body,s_args)
| 684 | |
| 685 | |
| 686 | def exec_script(self,script_id,script_body,s_args): |
| 687 | ''' |
| 688 | @name 执行脚本内容 |
| 689 | @param script_id<int> 脚本ID |
| 690 | @param script_body<string> 脚本内容 |
| 691 | @return dict |
| 692 | ''' |
| 693 | script_type = 'bash' |
| 694 | script_exts = {'bash':'sh','python':'py','php':'php','node':'js','ruby':'rb','perl':'pl'} |
| 695 | if script_id: |
| 696 | script_info = self._sql.table('scripts').where('script_id=?',(script_id,)).find() |
| 697 | if not script_info: |
| 698 | return False |
| 699 | script_body = script_info['script'] |
| 700 | script_type = script_info['script_type'] |
| 701 | |
| 702 | if not script_body: |
| 703 | return False |
| 704 | |
| 705 | if s_args: s_args = ' ' + s_args |
| 706 | |
| 707 | tmp_file = '{}/tmp/{}.{}'.format(public.get_panel_path(),public.GetRandomString(32),script_exts[script_type]) |
| 708 | public.writeFile(tmp_file,script_body) |
| 709 | |
| 710 | if script_type == 'bash': |
| 711 | result = public.ExecShell('bash {}{}'.format(tmp_file,s_args)) |
| 712 | elif script_type == 'python': |
| 713 | result = public.ExecShell('{} {}{}'.format(public.get_python_bin(),tmp_file,s_args)) |
| 714 | |
| 715 | if os.path.exists(tmp_file): |
| 716 | os.remove(tmp_file) |
| 717 | |
| 718 | return result |
| 719 | |
| 720 | def add_task_log(self,script_id,trigger_id,where_id,status,result_succ,result_err,start_time,end_time): |
| 721 | ''' |