#!/usr/bin/perl
use Device::SerialPort;
# Port with ups cable
$PORT=”/dev/ttyS0″;
# Connection Settings
$ob = new Device::SerialPort ($PORT) || die “Can’t open $PORT: $!\n”;
$ob->baudrate(2400);
$ob->parity(“none”);
$ob->databits(8);
# Send Y to put the ups in smart mode
$pass=$ob->write(“Y”);
# Send two Ks with > 1.5s delay between to shut down
$pass=$ob->write(“K”);
sleep 2;
$pass=$ob->write(“K”);
undef $ob;
# Now shutdown the computer. Hopefully, it’ll be shut down before the ups goes off
`/sbin/shutdown -h -t0 now`;