Handle hostnames with upper-case letters
[webmin.git] / at / macos-lib.pl
1 # macos-lib.pl
2
3 sub list_atjobs
4 {
5 local @rv;
6 opendir(DIR, $config{'at_dir'});
7 while($f = readdir(DIR)) {
8         local $p = "$config{'at_dir'}/$f";
9         if ($f =~ /^a(\S+)\.(\d+)$/) {
10                 local @st = stat($p);
11                 local $job = { 'id' => $f,
12                                'date' => hex($1)*60,
13                                'user' => scalar(getpwuid($st[4])),
14                                'created' => $st[9] };
15                 open(FILE, $p);
16                 while(<FILE>) {
17                         $job->{'cmd'} .= $_;
18                         }
19                 close(FILE);
20                 $job->{'realcmd'} = $job->{'cmd'};
21                 $job->{'realcmd'} =~ s/^[\000-\177]+cd\s+(\S+)\n//;
22                 push(@rv, $job);
23                 }
24         }
25 closedir(DIR);
26 return @rv;
27 }
28
29 # create_atjob(user, time, commands, directory, send-email)
30 sub create_atjob
31 {
32 local @tm = localtime($_[1]);
33 local $date = sprintf "%2.2d:%2.2d %d.%d.%d",
34                 $tm[2], $tm[1], $tm[3], $tm[4]+1, $tm[5]+1900;
35 local $mailflag = $_[4] ? "-m" : "";
36 &open_execute_command(AT, "su \"$_[0]\" -c \"cd $_[3] ; at $mailflag $date\" >/dev/null 2>&1", 0); 
37 print AT $_[2];
38 close(AT);
39 &additional_log('exec', undef, "su \"$_[0]\" -c \"cd $_[3] ; at $mailflag $date\"");
40 }
41
42 # delete_atjob(id)
43 sub delete_atjob
44 {
45 &system_logged("atrm \"$_[0]\" >/dev/null 2>&1");
46 }
47