I have to deal with a given file that contains crontab directives:
##Batch IdRef2Virtuoso
*/1 * * * * /home/batch/autorites/current/bin/exportAutorites2TS.sh > /dev/null 2>&1
*/1 * * * * /home/batch/autorites/current/bin/exportBiblio2TS.sh > /dev/null 2>&1
I want to cut it so as to get a yaml file with a list of items and then proceed with ansible. I'm able to do such a thing with regular awk:
while read -r line; do printf '%s\n' "$line"| awk '{ split($0, ip, /'\ '/); printf("- title1: \"%s\"\n title2: \"%s\"\n minute: \"%s\"\n hour: \"%s\"\n day_month: \"%s\"\n month: \"%s\"\n day_week: \"%s\"\n day: \"%s\"\n", ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8]);}'; done <"/tmp/crontab-DEV.txt"
Results in:
{
"msg": [
{
"day_month": "*",
"day_week": "*",
"hour": "*",
"job": "/home/batch/autorites/current/bin/exportAutorites2TS.sh",
"minute": "*/1",
"month": "*"
},
{
"day_month": "*",
"day_week": "*",
"hour": "*",
"job": "/home/batch/autorites/current/bin/exportBiblio2TS.sh",
"minute": "*/1",
"month": "*"
}
]
}
It works, but it is not very "ansible", how can I obtain the same result?