| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | #------------------------------------------------------------------------------ | ||
| 4 | # | ||
| 5 | # Standard pragmas | ||
| 6 | # | ||
| 7 | #------------------------------------------------------------------------------ | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | |||
| 11 | use Getopt::Long; | ||
| 12 | use App::Config; | ||
| 13 | use Net::SMS::O2; | ||
| 14 | |||
| 15 | my @options = qw( | ||
| 16 | username=s | ||
| 17 | password=s | ||
| 18 | recipient=s | ||
| 19 | subject=s | ||
| 20 | verbose | ||
| 21 | quota | ||
| 22 | audit_trail=s | ||
| 23 | message=s | ||
| 24 | file=s | ||
| 25 | ); | ||
| 26 | |||
| 27 | my $cfg_file = "$ENV{HOME}/.o2cfg"; | ||
| 28 | my %args; | ||
| 29 | if ( -e $cfg_file ) | ||
| 30 | { | ||
| 31 | my $ac = App::Config->new; | ||
| 32 | for ( qw( password username subject recipient ) ) | ||
| 33 | { | ||
| 34 | $ac->define( $_ ); | ||
| 35 | } | ||
| 36 | $ac->cfg_file( $cfg_file ); | ||
| 37 | %args = map { $_ => $ac->get( $_ ) } qw( password username subject recipient ); | ||
| 38 | } | ||
| 39 | die <<USAGE unless GetOptions( \%args, @options ); | ||
| 40 | $0 | ||
| 41 | -username <username> | ||
| 42 | -password <password> | ||
| 43 | -recipient <mobile no.> | ||
| 44 | [ -subject <subject> ] | ||
| 45 | [ -audit_trail <audit trail dir> ] | ||
| 46 | [ -verbose ] | ||
| 47 | [ -quota ] | ||
| 48 | [ -message message ] | ||
| 49 | [ -file message_file ] | ||
| 50 | |||
| 51 | USAGE | ||
| 52 | |||
| 53 | if ( $args{file} ) | ||
| 54 | { | ||
| 55 | open( FH, $args{file} ) or die "Can't open message file $args{file}\n"; | ||
| 56 | $args{message} = join( '', <FH> ); | ||
| 57 | close( FH ); | ||
| 58 | } | ||
| 59 | |||
| 60 | my $sms = Net::SMS::O2->new( %args ); | ||
| 61 | |||
| 62 | if ( $args{quota} ) | ||
| 63 | { | ||
| 64 | for my $type ( qw( free paid ) ) | ||
| 65 | { | ||
| 66 | print $sms->quota( $type ), " $type txts remaining\n"; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | if ( $args{message} ) | ||
| 70 | { | ||
| 71 | $sms->send_sms(); | ||
| 72 | } |