Unfortunatelly some scripts run with parameters, and some with configuration files
I need to find a way to add extra ;s so I can properly inport the columns into excel
Like:
One wonders why, initially, but I'm sure there is a reason. The file would have to be imported into Excel as a delimited text file if you are using ; as the separator.
It looks like you want the format of the time controls first, followed by the first script and then up to four more ; separated fields, kind of right-justified, which seems a little odd. Left justified would be easier:-
crontab -l|while read mins hours day_of_mon month day_of_week f1 f2 f3 f4 f5
do
echo "${mins};${hours};${day_of_mon month};${day_of_week};${f1};${f2};${f3};${f4};${f5}"
done > crontab.txt
To get right justified, you would need to adjust the values of f2 to f5, so:-
crontab -l|while read mins hours day_of_mon month day_of_week f1 f2 f3 f4 f5
do
if [ "$f2" != "" ]
then
while [ "$f5" = "" ]
do
f5="${f4}"
f4="${f3}"
f3="${f2}"
f2=""
done
fi
echo "${mins};${hours};${day_of_mon month};${day_of_week};${f1};${f2};${f3};${f4};${f5}"
done > crontab.txt
That should shuffle items (except the first script) to the right.
Does this acheive the results you are after? If not, please write back and we'll have another look.
So, how do you know which records have them and which do not?
In either case, the second chunk of code should do it. I'm still wondering why you need this, but......
If you are not getting the output you need, can you paste in the output of crontab -l and then the output you would want for a sample of the lines.
Maybe I've missed the point here, but if you want to import your crontab into Excel, why not just do it with the raw file using white space as the delimiter?
Each crontab line has 6 entries - minute, hour, day, month, day of week, command, so each will appear in a different column. Commands will be split across columns 6 to last, so you can process those at will in the spreadsheet
Is that near to what is required? It looks rather messy to me, probably because the input has lots of extra spaces in it. If this represents all of the input from crontab -l then you will need to recode my suggestion to cater for that. It is picking up the date bit okay, but the next "field" I'm calling f1 is selected as just (. then f2 gets .profile and f3 is ; which makes no sense.