msgat - skrypt do wysyłania powiadomień o określonym czasie lub za określony odstęp czasu. Wymaga zainstalowanej biblioteki libnotify (sudo apt-get install libnotify). Powiadomienia są ważne tylko na czas trwania bieżącej sesji.
Powiadomienia w środowisku Gnome wyglądają tak:

a wysyłać można je na kilka sposobów, np. dwa różne polecenia:
Kod: Zaznacz cały
msgat 2h55m bardzo ważna wiadomość
msgat 3h-5m "bardzo ważna wiadomość"
dadzą taki sam efekt, wyświetlą chmurkę w narożniku ekranu za 2 godziny i 55 minut (lub inaczej 3 godziny odjąć 5 minut). Rozpoznawane jednostki czasu to: w d h m - week, day, hour, minute.
Można również określić czas wprost, np. te dwa polecenia:
Kod: Zaznacz cały
msgat 20:45 31.07.08 'treść wiadomości'
msgat 2008-07-31 20:45 treść wiadomości
również dają ten sam efekt. W przypadku pominięcia jednego z parametrów daty lub czasu, przyjmowana jest aktualna data lub godzina.
Kod: Zaznacz cały
#!/bin/bash
#program: msgat v0.2
#author: Tomek Bekas
#email: procek <at> <no spam> gmail.com
#licence: GPL v3.0
#notes: the program sends a message to the user at a specific time or a
#specified interval of time, uses the program at and the library libnotify;
#notifications are active only during the current session;
#all error messages are routed from stderr to /dev/null, because almost
#all of them are warning messages sent to stderr even if everything works
#well, but if you want to review them, change the contents of ERRLOG variable
#usage examples:
#msgat 2009-01-31 20:45 content #these two different commands will give
#msgat 20:45 31.01.09 content #the same effect
#msgat 1w2d23h30m part1 part2 #and these two also give the same effect
#msgat 1w3d-30m "part1 part2" #
TFS=':' #time field separator, default is colon
DFS='.-' #date field separator, default is dot and dash
NFS='0123456789-' #numeric field separator, default is all digits and minus
DIFS="$IFS"
BU="minute" #basic unit, default is minute
TU=(w d h m) #time units, default is w d h m (weeks, days, hours, minutes)
UV=(7 24 60 1) #relative unit values
TIFS=$(echo ${TU[*]} | tr -d "${IFS:0:1}") #time interval field separator, default is 'wdhm'
ERRLOG="/dev/null" #error log file, default /dev/null :)
#set -x
function exitSuccess {
echo -en "message: $@\nwill be sent at: "
if [ "$interval" ] ; then
date -d"+$interval $BU" +"%a %d %b, %R"
else
date -d"$date $time" +"%a %d %b, %R"
fi
exit 0
}
function exitUsage {
echo -e "usage: \n$0 [time] [date] <message>\n$0 [interval] <message>"
exit 1
}
function checkLibnotify {
if [ ! -x /usr/bin/notify-send ] ; then
echo "you need to have libnotify installed to run this script"
exit 1
fi
}
function absUnitValue
(
result=1
for (( i=$[ ${#UV[*]} - 1 ] ; i >= 0 ; i-- )) ; do
result=$[ $result * ${UV[i]} ]
[ "$1" = "${TU[i]}" ] && { echo $result ; exit 0 ; }
done
echo 0 #if unit not found in array
exit 1
)
function getTime
(
arg=$1
IFS=$TFS
set $1
IFS=$DIFS
[ $# -ne 2 ] && exit 1
arg=`date -d"${1}:${2}" +%R` || exit 1 #generates errors to stderr
echo $arg
exit 0
)
function getDate
(
arg=$1
IFS=$DFS
set $1
IFS=$DIFS
[ $# -ne 3 ] && exit 1
arg=`date -d"${3}-${2}-${1}" +%F` || #generates errors to stderr
arg=`date -d"${1}-${2}-${3}" +%F` || exit 1 #generates errors to stderr
echo $arg
exit 0
)
function getInterval
(
arg=$1
IFS=$NFS
set $arg
units=$@ #units used in arg
IFS=$TIFS
set $arg
IFS=$DIFS
for i in $units ; do
sum=$[ $sum + $1 * $(absUnitValue $i) ] || exit 1 #generates errors to stderr
shift
done
echo $sum
exit 0
)
function sendMsg
(
if [ "$interval" ] ; then
#generates errors to stderr
at "now + $interval $BU" << EOT
notify-send -t 0 "$@"
EOT
(( $? )) && exit 1
else
#generates errors to stderr
#at "${time:=$(date +%R)} ${date:=$(date +%F)}" << EOT
at "$time $date" << EOT
notify-send -t 0 "$@"
EOT
(( $? )) && exit 1
fi
exit 0
)
function main {
checkLibnotify
[ $# -lt 2 ] && exitUsage #requires at least two arguments
date=''
time=''
interval=''
for i ; do
#if interval and date and time are empty
if [ -z "$interval" -a -z "$date" -a -z "$time" ] ; then
interval=`getInterval $1` || #the only proper order is interval, time, date
time=`getTime $1` ||
date=`getDate $1` || exitUsage
shift
#if only date and interval are empty (time has some value)
elif [ -z "$date" -a -z "$interval" ] ; then
date=`getDate $1` && shift || date=`date +%F`
sendMsg $@ && exitSuccess $@ || exitUsage
#if only time and interval are empty (date has some value)
elif [ -z "$time" -a -z "$interval" ] ; then
time=`getTime $1` && shift || time=`date +%R`
sendMsg $@ && exitSuccess $@ || exitUsage
#if only time and date are empty (interval has some value)
else #equal to: if [ -z "$time" -a -z "$date" ] ; then
sendMsg $@ && exitSuccess $@ || exitUsage
fi
done
}
main $@ 2> $ERRLOG #stderr > /dev/null