Lo más sencillo para lograr esto es crear en /etc/crontab
siguiente tarea:
@reboot /path/to/your/python/script.sh
Puede obtener más información de man 5 crontab .
CoreOS no tiene /etc/crontab
.
Otra forma es crear systemd -timer . Ejemplo sobre el temporizador systemd -que puede obtener de mi respuesta sobre systemd:Use systemd -shutdownd schedule .
Ejemplo simple del temporizador systemd -que se encuentra en/etc/systemd/system/example.timer
:
[Unit]
Description=Run once at system boot
[Timer]
# You may chose one of this triggers
OnBootSec=0min # run after system boot
OnStartupSec=0min # run after systemd was started
[Install]
WantedBy=timers.target # target in wich timer will be installed
Давайте сначала зафиксируем разделенные строки, пренебрегая разделенными столбцами:
$ grep -v "^\s*[^ ]*$" file | grep -o "[^ ]*" | paste - - - - - -
G00PFMA1 transition_readonly 2 cifs 0.0.0.0/0 any
G00PFMA7 transition_export_policy_1 1 nfs 10.58.91.134 sys
G00PFMA7 transition_export_policy_1 2 nfs bmczone.tsy.fm. sys
G00PFMA7 transition_export_policy_1 3 nfs inf01mz2 sys
Пояснение:
Отфильтровать строки, содержащие только один элемент:
grep -v "^\s*[^ ]*$" file
Поместить все элементы в отдельную строку
grep -o "[^ ]*"
Соедините их вместе до шести столбцов в строке
paste - - - - - -
Я получил хакерское полное решение, которое может быть достаточно хорошим для ваших нужд, но не является ни красивым, ни очень переносимым. Предполагается, что единственный разделяемый столбец — это столбец #5, и что у нас всегда будет 6 столбцов.
{
print_items(){
# print if there are 6 elements
if [ $# = 6 ]; then
echo "$@"
# print if there are 7 elements, but merge element 5 and 7 before printing
elif [ $# = 7 ]; then
set -- "${@:1:4}" "${5}${7}" "${@:6:1}"
echo "$@"
fi
}
items=()
while IFS= read -r line; do
# Get start position of first item
start_position=$(grep -o "^ *" <<< "$line" | wc -c)
# if start_position is 0 then create new array items with elements in the line
if [ $start_position = 0 ]; then
# when new line starts, print previous line
print_items "${items[@]}"
items=( $line )
# if start_position is not 0, add the elements in the line to the existing items array
else
items+=( $line )
fi
# Print items
done < file
# print last line
print_items "${items[@]}"
} | column -t
Выход:
G00PFMA1 transition_readonly 2 cifs 0.0.0.0/0 any
G00PFMA7 transition_export_policy_1 1 nfs 10.58.91.134 sys
G00PFMA7 transition_export_policy_1 2 nfs bmczone.tsy.fm.hypovereinsbank.de sys
G00PFMA7 transition_export_policy_1 3 nfs inf01mz2 sys