From 0fdc98393f58b2a50788d46db4354836ae30c9c3 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 14 Mar 2019 06:18:55 +0000 Subject: [PATCH] bin/cron_d2crontab --- bin/cron_d2crontab | 28 +++++++++------------------- etc/profile.d/functions | 1 + 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/bin/cron_d2crontab b/bin/cron_d2crontab index be81e864..d605bd2f 100755 --- a/bin/cron_d2crontab +++ b/bin/cron_d2crontab @@ -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; diff --git a/etc/profile.d/functions b/etc/profile.d/functions index da7126d3..0627aa8a 100755 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -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" -- 2.47.3