function usage { echo "Usage: ${O##*/} (format: \"%Y-%m-%d %H:%M:%S\")> \"\"" echo " format dates: \"%Y-%m-%d %H:%M:%S\"" echo " ex: nagios_downtime_w_childs.sh switch1 \"2021-01-15 07:18:00\" \"2021-01-15 07:48:00\" \"test downtime 30min\"" exit 1 } [ -z "$4" ] && usage now=$(date +%s) commandfile='/var/nagios/rw/nagios.cmd' # affectation et contrôle des inputs naghost=$1 debut=$(date -d "$2" +%s 2>/dev/null) [ -z "$debut" ] && { echo "Date début $2 invalide !"; usage; } #[[ "$3" =~ ^[0-9]*$ ]] && fin=`expr $debut + $3` || { echo "ERR: Durée $3 invalide !"; usage; } fin=$(date -d "$3" +%s 2>/dev/null) [ -z "$fin" ] && { echo "Date fin $3 invalide !"; usage; } comment="$4" /usr/bin/printf "[%lu] SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;$naghost;$debut;$fin;1;0;7200;toto;$comment\n" $now > $commandfile