"Fossies" - the Fresh Open Source Software archive 
#!/usr/bin/perl -T
# Put a job into samsemd's spool directory
# Version 0.3
#
# File format
# class 0|1|2|3|default (optional)
# validity <validity period> (optional)
# ack (optional)
# number <destination number> (mandatory)
# msg <multiline text up to the end of file> (mandatory)
$SPOOLDIR = '/tmp/samsemd'; # Customize this
$VERSION="0.3";
$0 =~ s|.*/||;
require 'getopts.pl';
Getopts("v:c:s:a") or usage(); # program exits
$number = shift; # alias|number
$#ARGV >= 0 or usage(); # program exits
$opt_s and $SPOOLDIR=$opt_s;
$pidfile = "$SPOOLDIR/pid";
$file = "$SPOOLDIR/tmp.$$";
open(FILE,">$file") or die "$0: Can't open file '$file', $!";
if ($opt_v =~ /^((\d*\.\d+)|\d+\s*)[mhdw]$/) {
print FILE "validity $opt_v\n";
}
if ($opt_c =~ /[0-3]|(default)/) {
print FILE "class $opt_c\n";
}
if ($opt_a) {
print FILE "ack\n";
}
print FILE "number $number\nmsg @ARGV\n";
close FILE;
for (0..3) {
link($file, "$SPOOLDIR/send." . time . "." . '0' x $_ . $$) or next;
unlink $file;
}
-f $file and die "$0: Cannot enqueue file '$file'\n";
if (-f $pidfile) {
open(PID,$pidfile) or exit; # samsemd is not running
$pid = <PID>;
close PID;
$pid =~ /^(\d+)$/ or exit; # incorrect pidfile
kill 'USR1' => $1; # wakeup samsemd
}
exit;
###############################
# Never returns
sub usage {
print <<END;
$0 version $VERSION
Usage: $0 [-s spooldir] [-v validity] [-c class] [-a] phone_number|name message
Where:
-s spooldir: Spool directory. The default value ($SPOOLDIR) is
hardcoded into the program text. Customize it.
-v time: Validity Period. A real number and one of m|h|d|w (i.e.
minute/hour/day/week). E.g. "2.5d".
-c class: Message class. 0-3 or "default"
(class 0=display, 1=phone memory, 2=SIM memory, 3=terminal)
-a: Request status report.
Phone number: "+international_number" or "national_number"
(digits may be mixed with spaces and dashes)
Name: An item of the phonebook of samsemd.
END
exit 3;
}