]> git.nbdom.net Git - nb.git/commitdiff
bin/cron_d2crontab
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 14 Mar 2019 06:18:55 +0000 (06:18 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 14 Mar 2019 06:18:55 +0000 (06:18 +0000)
bin/cron_d2crontab
etc/profile.d/functions

index be81e86433d424efd556977a5cfe95858e67e7fe..d605bd2f357fe2957fd904139b14017c2effa57c 100755 (executable)
@@ -10,11 +10,6 @@ my $VERSION = '0.0.1';
 # NB 14.03.19
 # - create script: ?
 
-#################################################################################
-#
-# GLOBALS
-#
-#################################################################################
 my ($NAME) = $0 =~ m,([^/]+)$,;
 
 #################################################################################
@@ -43,7 +38,7 @@ my $exp = shift @ARGV;
 #
 # Parse src file
 #
-my @src = map {chomp; $_} grep {/^(\w+=|\*|\d+)/} <>;
+my @src = map {chomp; $_} grep {/^(\w+=|\*|\d+|@)/} <>;
 
 for (my $i=0;$i<@src;$i++) {
 
@@ -52,27 +47,22 @@ for (my $i=0;$i<@src;$i++) {
        if (@_=/^
                (
                        (?:[\*\d\/-]+\s+){5}
-                       |(?:@\w+\s+)
+                       |(?:\@\w+\s+)
                )
        (\S+)\s+(.*)$/x) {
                my $when = $1; chop $when;
                my $user = $2;
                my $cmd = $3;
-               print Dumper(\@_);
-               exit;
+               if ($user ne "root"){
+                $_ = join(" ",$when,$cmd);
+                s/"/\\"/g;
+                $src[$i] = qq|su -l "$user" -c "$_"|;
+               };
+               #print Dumper(\@_); exit;
        }
-       my @F = split(" ",$src[$i]);
-
-       next if $src[$i] !~ /^[\*\d]/ or @F<6;
-       if ($F[5] ne "root"){
-        $_ = join(" ",@F[6..$#F]);
-        s/"/\\"/g;
-        @_=qq|su -l "$F[5]" -c "$_"|;
-        @F = (@F[0..4],"",@_);
-       };
 
-       $src[$i] = join(" ",@F[0..4,6..$#F]);
 }
+0 and die join("\n",@src);
 0 and warn join("\n",@src);
 my %src = map {$_=>1} @src;
 
index da7126d35b542ec55504a0237a2e90961bbcbf51..0627aa8a9f9f546176c13a72584b5316feb293b8 100755 (executable)
@@ -912,6 +912,7 @@ exit $diff ? 0 : 1;
 ' "$exp" "$file"
 )
 
+       cron=$(cron_d2crontab "$exp" "$file")
        if [ "$test" = "1" ]; then
                printf '%s' "$FUNCNAME: crontab: $fname"
                #echo -e "\n<\n$(crontab -l)\n>\n<\n$cron\n>\n"