This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
sermn_wiki:userpages:marta:reserves_automatiques_manteniment [2013/10/18 14:46] miquel created |
sermn_wiki:userpages:marta:reserves_automatiques_manteniment [2022/08/19 15:32] miquel [Reserves automàtiques per l'estona de Manteniment (de 2013-10 a 2022-03)] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Reserves automàtiques per l' | + | ====== Reserves automàtiques per l' |
- | FIXME explicar el programet per fer les reserves automàtiques per l'estona | + | <WRAP info> |
+ | Els scripts i les tasques periòdiques programades ('' | ||
- | ===== service_bookings.sh ===== | + | La informació sobre els nous scripts i tasques periòdiques programades es troba a la pàgina [[sermn_wiki: |
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Després de veure que les [[sermn_wiki: | ||
+ | * fins ara les estones de manteniment estaven programades als horaris dels espectròmetres i eren fixes; | ||
+ | * a partir d' | ||
+ | |||
+ | És a dir, si cal, es podran modificar les reserves de les estones de manteniment. Per exemple: | ||
+ | * si es canvia el dia de manteniment, | ||
+ | * si la recàrrega de nitrogen líquid finalitza força abans que l' | ||
+ | * si algú vol reservar un espectròmetre el dia de manteniment i l' | ||
+ | |||
+ | **IMPORTANT: | ||
+ | |||
+ | |||
+ | ===== maintenance_bookings.sh ===== | ||
+ | |||
+ | Aquest es el programet que crea les reserves per l' | ||
+ | |||
+ | <code bash maintenance_bookings.sh> | ||
+ | # | ||
+ | # | ||
+ | # maintenance_bookings.sh | ||
+ | # | ||
+ | # (c) 2013, Miquel Cabanas, SeRMN, UAB | ||
+ | # | ||
+ | # Started writing: | ||
+ | # Last updated: | ||
+ | # | ||
+ | # This script runs the MySql commands needed to automatically create the | ||
+ | # bookings for the spectrometers maintenance tasks, mainly liquid nitrogen | ||
+ | # refills. | ||
+ | # | ||
+ | # To run this script every Sunday 2am append an entry like, | ||
+ | # | ||
+ | # FIXME 0 3 * * Sun / | ||
+ | # | ||
+ | # to crontab. This entry means, at minute 0, hour 2, on every (*) day of | ||
+ | # the month and on every (*) month of the year, if that day happens to be | ||
+ | # a Sunday (day 0), execute the commands in the script file | ||
+ | # ' | ||
+ | |||
+ | |||
+ | # VARIABLES --------------------------------------------------------------- | ||
+ | |||
+ | # programs | ||
+ | # | ||
+ | date=`which date` | ||
+ | mail=`which mail` | ||
+ | mysql=`which mysql` | ||
+ | |||
+ | # email recipients and subject | ||
+ | |||
+ | to_address=" | ||
+ | # cc_address=" | ||
+ | cc_address=" | ||
+ | subject=" | ||
+ | |||
+ | # date related variables. This script runs on Sunday, and bookings are made | ||
+ | # eight weeks in advance (56 days) on Wednesday from 09:00 to 13:00. Hence, | ||
+ | # we need to find those dates so that we can use them later when booking time-slots. | ||
+ | # | ||
+ | # NOTE: these date variables are not currently used for booking commands, | ||
+ | # only for the reporting email messages. | ||
+ | |||
+ | today_date=`$date --date=' | ||
+ | mon_date_mail=`$date --date=' | ||
+ | mon_weekno=`$date --date=' | ||
+ | |||
+ | # Bumblebee booking system database where everything gets stored | ||
+ | |||
+ | myuser=' | ||
+ | mypass=' | ||
+ | mydb=' | ||
+ | |||
+ | |||
+ | # INSERT BOOKING ENTRIES IN THE DATABAE ----------------------------------------- | ||
+ | |||
+ | $mysql --database=$mydb --user=$myuser --password=$mypass << EOF | ||
+ | /* begin transaction */ | ||
+ | BEGIN; | ||
+ | /* Insert bookings for weekly maintenance tasks in all vertical magnets. */ | ||
+ | /* By default, book Wednesday morning from 09:00 to 13:00, 8 weeks in advance */ | ||
+ | /* (i.e. 59 days) */ | ||
+ | |||
+ | /* Avance DPX-250-QNP (250-AUTO) - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Avance DPX-250-BACS (250-ROBOT) - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Avance DPX-360 - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* AvanceIII 400SB - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* AvanceII 400WB - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Avance DRX-500 - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* AvanceII+ 600 - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Hypersense DNP - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* commit transaction */ | ||
+ | COMMIT; | ||
+ | EOF | ||
+ | |||
+ | |||
+ | # MAIL THE SYSTEM AND INSTRUMENT ADMINISTRATORS - ----------------------- | ||
+ | # | ||
+ | # Report to the system and instrument administrators whether Routine NMR | ||
+ | # bookings have been created. | ||
+ | # | ||
+ | status=$? | ||
+ | |||
+ | if [ $status -ne 0 ]; then | ||
+ | # mysql command failed. Send an email reporting the failure | ||
+ | # | ||
+ | $mail -s " | ||
+ | |||
+ | AUTOMATED EMAIL MESSAGE. DO NOT REPLY | ||
+ | |||
+ | SeRMN - Universitat Autonoma de Barcelona | ||
+ | |||
+ | Failed to allocate time slots for weekly maintenance tasks | ||
+ | week $mon_weekno starting: $mon_date_mail. | ||
+ | |||
+ | Please, report this issue to the system administrator. | ||
+ | |||
+ | EOM | ||
+ | |||
+ | else | ||
+ | # mysql command suceeded. Send an email reporting that routine | ||
+ | # bookings have been created | ||
+ | # | ||
+ | $mail -s " | ||
+ | |||
+ | AUTOMATED EMAIL MESSAGE. DO NOT REPLY | ||
+ | |||
+ | SeRMN - Universitat Autonoma de Barcelona | ||
+ | |||
+ | Time slots have been allocated for weekly maintenance tasks | ||
+ | on all SeRMN spectrometers for week $mon_weekno starting: | ||
+ | $mon_date_mail. | ||
+ | |||
+ | EOM | ||
+ | |||
+ | fi | ||
+ | |||
+ | exit | ||
+ | </ | ||
+ | |||
+ | El programet envia el següent correu electrònic si ha aconseguit fer les reserves, | ||
+ | |||
+ | < | ||
+ | -------- Original Message -------- | ||
+ | Subject: SeRMN Booking System - Weekly maintenance reservations | ||
+ | Date: Sun, 27 Oct 2013 16:54:46 +0300 | ||
+ | From: root < | ||
+ | To: Miquel.Cabanas@uab.cat | ||
+ | |||
+ | AUTOMATED EMAIL MESSAGE. DO NOT REPLY | ||
+ | |||
+ | SeRMN - Universitat Autonoma de Barcelona | ||
+ | |||
+ | Time slots have been allocated for weekly maintenance tasks | ||
+ | on all SeRMN spectrometers for week 52/2013 starting: | ||
+ | Mon 2013/ | ||
+ | </ | ||
+ | |||
+ | i aquest altre missatge en cas contrari, | ||
+ | |||
+ | < | ||
+ | -------- Original Message -------- | ||
+ | Subject: SeRMN Booking System - NMR Routine reservations | ||
+ | Date: Sun, 27 Oct 2013 16:54:46 +0300 | ||
+ | From: root < | ||
+ | To: Miquel.Cabanas@uab.cat | ||
+ | |||
+ | AUTOMATED EMAIL MESSAGE. DO NOT REPLY | ||
+ | |||
+ | SeRMN - Universitat Autonoma de Barcelona | ||
+ | |||
+ | Failed to allocate time slots for weekly maintenance tasks | ||
+ | week 52/2013 starting: Mon 2013/ | ||
+ | |||
+ | Please, report this issue to the system administrator. | ||
+ | </ | ||
+ | |||
+ | ===== Entrada al registre crontab ===== | ||
+ | |||
+ | Aquesta és l' | ||
+ | |||
+ | < | ||
+ | # Bumblebee 1.1.4 - Automated bookings for weekly maintenance tasks. It runs | ||
+ | # on Sunday at 03:00. | ||
+ | # | ||
+ | 0 | ||
+ | </ | ||
- | Aquest es el programet que crea les reserves per l' | ||
===== Seguretat ===== | ===== Seguretat ===== | ||
Per motius de seguretat (el programet conté el nom d' | Per motius de seguretat (el programet conté el nom d' | ||
- | * permisos: | + | * permisos |
+ | * permisos fitxer '' | ||
* propietari (user: | * propietari (user: | ||
Line 21: | Line 228: | ||
+ | ===== Recreació de les reserves antigues ===== | ||
+ | |||
+ | Aquest canvi a l' | ||
+ | |||
+ | <code bash create_past_maintenance_bookings.sh> | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # create_past_maintenance_bookings.sh | ||
+ | # | ||
+ | # (c) 2013, Miquel Cabanas, SeRMN, UAB | ||
+ | # | ||
+ | # Started writing: | ||
+ | # Last updated: | ||
+ | # | ||
+ | # This script runs the MySql commands needed to create the maintenance | ||
+ | # bookings needed to replace the past maintenance periods that were set | ||
+ | # in the spectrometer schedules and have been replaced now by real bookings. | ||
+ | # | ||
+ | |||
+ | # programs | ||
+ | |||
+ | date=`which date` | ||
+ | mail=`which mail` | ||
+ | mysql=`which mysql` | ||
+ | |||
+ | # Bumblebee booking system database where everything gets stored | ||
+ | |||
+ | myuser=' | ||
+ | mypass=' | ||
+ | mydb=' | ||
+ | |||
+ | # First Wednesday on a particular year | ||
+ | |||
+ | firstwed=`$date +%F -d " | ||
+ | echo "First wednesday (included): $firstwed" | ||
+ | |||
+ | # Last Wednesday on a particular year | ||
+ | |||
+ | lastwed=`$date +%F -d " | ||
+ | echo "Last wednesday (excluded): $lastwed" | ||
+ | |||
+ | # insert booking entries in the database | ||
+ | |||
+ | wed=$firstwed | ||
+ | |||
+ | while [[ " | ||
+ | |||
+ | echo " | ||
+ | |||
+ | $mysql --database=$mydb --user=$myuser --password=$mypass << EOF | ||
+ | /* begin transaction */ | ||
+ | BEGIN; | ||
+ | /* Insert bookings for weekly maintenance tasks in all vertical magnets. */ | ||
+ | /* By default, book Wednesday morning from 09:00 to 13:00, 8 weeks in advance | ||
+ | |||
+ | /* Avance DPX-250-QNP (250-AUTO) - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Avance DPX-250-BACS (250-ROBOT) - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Avance DPX-360 - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* AvanceIII 400SB - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* AvanceII 400WB - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Avance DRX-500 - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* AvanceII+ 600 - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* Hypersense DNP - Wednesday from 09:00 to 13:00 -> 4 hours */ | ||
+ | INSERT INTO bookings(bookwhen, | ||
+ | |||
+ | /* commit transaction */ | ||
+ | COMMIT; | ||
+ | EOF | ||
+ | |||
+ | wed=`$date +%F -d "$wed + 1 week"` | ||
+ | |||
+ | done | ||
+ | exit | ||
+ | </ | ||