Initial commit for Tizen
[profile/extras/shadow-utils.git] / contrib / atudel
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 1996 Brian R. Gaeke
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 #    must display the following acknowledgement:
16 #    This product includes software developed by Brian R. Gaeke.
17 # 4. The name of the author, Brian R. Gaeke, may not be used to endorse
18 #    or promote products derived from this software without specific
19 #    prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY BRIAN R. GAEKE ``AS IS'' AND ANY EXPRESS
22 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 # DISCLAIMED.  IN NO EVENT SHALL BRIAN R. GAEKE BE LIABLE FOR ANY DIRECT,
25 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 # Additionally:
34 #
35 # This software is provided without support and without any obligation
36 # on the part of Brian R. Gaeke to assist in its use, correction,
37 # modification or enhancement.
38 #
39 #######################################################################
40 #
41 # this is atudel, version 2, by Brian R. Gaeke <brg@dgate.org>
42 #
43
44 require "getopts.pl";
45 &Getopts('v');
46 $username = shift(@ARGV);
47 &usage unless $username;
48
49 sub usage
50 {
51         print STDERR "atudel - remove all at jobs owned by a user\n";
52         print STDERR "usage: $0 [-v] username\n";
53         exit(1);
54 }
55
56 # odd. unless getpwnam($uname) doesn't seem to work for $uname eq "root" on
57 # my linux system. but this does.
58 die "user $username does not exist; stopping"
59         unless defined(getpwnam($username));
60
61 print "searching for at jobs owned by user $username ..." if $opt_v;
62
63 chdir "/var/spool/atjobs" ||
64         die "can't chdir to /var/spool/atjobs: $!\nstopping";
65 opendir(DIR,".") || die "can't opendir(/var/spool/atjobs): $!\nstopping";
66 @files = grep(!/^\./,grep(-f,readdir(DIR)));
67 closedir DIR;
68
69 foreach $x (@files)
70 {
71         $owner = (getpwuid((stat($x))[4]))[0];
72         push(@nuke_bait,$x) if $owner eq $username;
73 }
74
75 if (@nuke_bait)
76 {
77         print "removed jobIDs: @{nuke_bait}.\n" if $opt_v;
78         unlink @nuke_bait;
79 }
80 elsif ($opt_v)
81 {
82         print "\n";
83 }
84
85 exit 0;