3 # Execute an existing cron job, and display the output
5 require './cron-lib.pl';
8 @jobs = &list_cron_jobs();
9 $job = $jobs[$in{'idx'}];
10 &can_edit_user(\%access, $job->{'user'}) || &error($text{'exec_ecannot'});
11 &foreign_require("proc", "proc-lib.pl");
13 # split command into command and input
15 &convert_comment($job);
16 $job->{'command'} =~ s/\\%/\0/g;
17 @lines = split(/%/ , $job->{'command'});
18 foreach (@lines) { s/\0/%/g; }
19 for($i=1; $i<@lines; $i++) {
20 $input .= $lines[$i]."\n";
24 &ui_print_header(undef, $text{'exec_title'}, "");
27 &ui_print_unbuffered_header(undef, $text{'exec_title'}, "");
29 &additional_log('exec', undef, $lines[0]);
30 &webmin_log("exec", "cron", $job->{'user'}, $job);
32 # Remove variables that wouldn't be in the 'real' cron
35 # Set cron environment variables
36 foreach $e (&read_envs($job->{'user'})) {
37 $ENV{$1} = $2 if ($e =~ /^(\S+)\s+(.*)$/);
40 if (&supports_users()) {
41 # Get command and switch uid/gid
42 @uinfo = getpwnam($job->{'user'});
43 $ENV{"HOME"} = $uinfo[7];
44 $ENV{"SHELL"} = "/bin/sh";
45 $ENV{"LOGNAME"} = $ENV{"USER"} = $job->{'user'};
46 &switch_to_unix_user(\@uinfo);
51 print &text('exec_cmdbg',
52 "<tt>".&html_escape($lines[0])."</tt>"),"<p>\n";
53 if (defined($input)) {
54 local $temp = &tempname();
55 &open_tempfile(TEMP, ">$temp");
56 &print_tempfile(TEMP, $input);
57 &close_tempfile(TEMP);
58 &execute_command("(($lines[0]) ; rm -f $temp) &", $temp,
62 &execute_command("($lines[0]) &", undef, undef, undef);
66 # Execute cron command and display output..
67 print &text('exec_cmd',
68 "<tt>".&html_escape($lines[0])."</tt>"),"<p>\n";
70 $got = &foreign_call("proc", "safe_process_exec",
71 $lines[0], 0, 0, STDOUT, $input, 1);
72 print "<i>$text{'exec_none'}</i>\n" if (!$got);
76 &ui_print_footer("edit_cron.cgi?idx=$in{'idx'}", $text{'edit_return'},
77 "", $text{'index_return'});