Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ########################################################################
- # Author: Henning Hollermann, laclaro@mail.com #
- # #
- # This program is free software: you can redistribute it and/or #
- # modify it under the terms of the GNU General Public License #
- # as published by the Free Software Foundation, either version 3 #
- # of the License, or (at your option) any later version #
- # #
- # This program is distributed in the hope that it will be useful, #
- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
- # GNU General Public License for more details. #
- # #
- # You should have received a copy of the GNU General Public License #
- # along with this program. If not, see <http://gnu.org/licenses/>. #
- # #
- # Bash-Script read list of birthday dates and names with lines #
- # "dd.mm.yyyy NAME" and prints birthdays that are nearby as con- #
- # figured. #
- # #
- # Written in simple bash and awk . #
- # #
- ########################################################################
- # SETTINGS
- birthday_list=$HOME/.geburtstagsliste
- TOLERANCE=5
- DAY="$(date +%d)"
- MONTH="$(date +%m)"
- YEAR="$(date +%Y)"
- # Sort file every 6 hours
- SORT=6
- # START SCRIPT
- if [ ! -r $birthday_list ]; then
- echo "Error: file $birthday_list not found or not readable." 1>&2
- exit 1
- fi
- # sort list (so you can easily add birthdays, right at the bottom)
- if [ $(find $birthday_list -mmin +$(($SORT*60)) -type f 2>/dev/null) ]; then
- sort -n +1 -2 -t'.' $birthday_list -o $birthday_list
- fi
- awk '
- BEGIN {FS="[.]+|[ \t]+"; N=0; };
- {if ( $2==('$MONTH') && $1<=('$DAY'+'$TOLERANCE') && $1>=('$DAY'-'$TOLERANCE') ) {
- day=$1; month=$2; year=$3; $1=$2=$3=""; gsub ("^[ \t]+", "", $0); name=$0;
- monthnamecommand="date --date="month"/"day" +%B";
- monthnamecommand | getline monthname;
- message = day". " monthname" "name;
- # if recent birthdays are present, add age
- if ('$YEAR'-year!='$YEAR') message = message " ("'$YEAR'-year")";
- # mark todays birthdays
- if (day == '$DAY') message="> "message;
- print message;
- N = N+1;
- }}
- END { if (N==0) print "Keine zeitnahen Geburtstage"}
- ' $birthday_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement