diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rwxr-xr-x | scripts/vyatta-gettime.pl | 44 | ||||
-rw-r--r-- | templates/show/shutdown/node.def | 8 | ||||
-rw-r--r-- | templates/shutdown/at/node.tag/node.def | 4 |
4 files changed, 56 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index a89a7be..df20bba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,6 +20,7 @@ bin_SCRIPTS += scripts/vyatta-tshark-interface-port.pl bin_SCRIPTS += scripts/vyatta-show-bonding.pl bin_SCRIPTS += scripts/vyatta-cpu-summary.pl bin_SCRIPTS += scripts/yesno +bin_SCRIPTS += scripts/vyatta-gettime.pl bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh diff --git a/scripts/vyatta-gettime.pl b/scripts/vyatta-gettime.pl new file mode 100755 index 0000000..ae0824b --- /dev/null +++ b/scripts/vyatta-gettime.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl +# +# Module: vyatta-gettime.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# 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. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Stephen Hemminger +# Date: March 2009 +# Description: Script to read time for shutdown +# +# **** End License **** +# + +use strict; +use warnings; +use Date::Format; + +sub gettime { + my $t = shift; + + return time2str( "%R", time ) if ( $t eq 'now' ); + return $t if ( $t =~ /^[0-9]+:[0-9]+/ ); + $t = substr( $t, 1 ) if ( $t =~ /^\+/ ); + return time2str( "%R", time + ( $_ * 60 ) ) if ( $t =~ /^[0-9]+/ ); + + die "invalid time format: $t\n"; +} + +# decode shutdown time +for (@ARGV) { + print gettime($_), "\n"; +} diff --git a/templates/show/shutdown/node.def b/templates/show/shutdown/node.def new file mode 100644 index 0000000..ecc8c4b --- /dev/null +++ b/templates/show/shutdown/node.def @@ -0,0 +1,8 @@ +help: Show scheduled shutdown +run: if [ -f /var/run/shutdown.pid ] + then if [ -r /tmp/shutdown.at ] + then echo -n "Shutdown pending at"; cat /tmp/shutdown.at + else echo "Shutdown pending" + fi + else echo "No shutdown pending" + fi diff --git a/templates/shutdown/at/node.tag/node.def b/templates/shutdown/at/node.tag/node.def index 13cbaa1..94cd332 100644 --- a/templates/shutdown/at/node.tag/node.def +++ b/templates/shutdown/at/node.tag/node.def @@ -1,3 +1,5 @@ help: Shutdown the system at a future time allowed: echo -n '<HH:MM>' '<MMDDYY>' '+MM' -run: sudo /sbin/shutdown -h $3 & +run: if /opt/vyatta/bin/vyatta-gettime.pl $3 >/tmp/shutdown.at + then sudo /sbin/shutdown -h $3 & + fi |