Created
June 5, 2014 10:06
-
-
Save takihito/c6afdb145ce69e388fda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# crontab -l | ./cron2cal > ~/tmp/cron.csv | |
use utf8; | |
use strict; | |
use warnings; | |
use Encode; | |
use DateTime; | |
my $comment; | |
my $cron; | |
print "Subject,Start Date,Start Time,End Date,End Time,All Day Event,Description,Location,Private\n"; | |
while ( <STDIN> ) { | |
my $stdin = $_; | |
$cron = ""; | |
chomp $stdin; | |
$comment = $stdin if $stdin =~ /^#/; | |
$cron = $stdin if $stdin =~ /^(\d)/; | |
next unless $cron; | |
my ($minute, $hour, $day, $month, $week, @com ) = split(' ', $cron); | |
# 明確な時刻指定がないもの(範囲指定/,分単位定期実行)は取り除く | |
next if $minute !~ /^\d+$/ || $hour !~ /^\d+$/; | |
my $dt = DateTime->now->set_time_zone('Asia/Tokyo'); | |
$dt->add(days => 1 ); | |
if ( $month =~ /^\d+$/ ) { | |
$dt->set_month($month) if $month =~ /^\d+$/; | |
} elsif( $day =~ /^\d+$/ && $day < $dt->day) { | |
$dt->add(months => 1 ); | |
} | |
$dt->set_day($day) if $day =~ /^\d+$/; | |
$dt->set_hour($hour) if $hour =~ /^\d+$/; | |
$dt->set_minute($minute) if $minute =~ /^\d+$/; | |
$dt->set_second(0); | |
my $Subject = "cron:".$comment; | |
my $Start_Date = $dt->strftime("%Y-%m-%d"); | |
my $Start_Time = $dt->strftime("%H:%M:%S"); | |
my $End_Date = $dt->add(minutes => 15 )->strftime("%Y-%m-%d"); | |
my $End_Time = $dt->strftime("%H:%M:%S"); | |
my $All_Day_Event = 'False'; | |
my $Description = join(' ', @com); | |
my $Location = "crontab"; | |
my $Private = 'True'; | |
my $row = join(',', $Subject,$Start_Date,$Start_Time,$End_Date,$End_Time,$All_Day_Event,$Description,$Location,$Private); | |
printf("%s\n", $row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こんな感じで実行して
Googleカレンダーへcron.csvをインポートすると、翌日のカレンダーにcrontabスケジュールが表示されます
https://support.google.com/calendar/answer/45656?hl=ja