#!/bin/bash # depends on googlecl Today="`date +%F`" Time="`date +%H%M%S`" gfile='/tmp/goog-'$Today'-'$Time tfile='/usr/local/freeswitch/conf/dialplan/default/tenants.xml' function prepwork { google docs get --title your-google-doc --format=csv --dest=$gfile # replace empty fields with 'null', to guarantee that our while loop will correctly match fields with variables. awk -F, '{for(i=1;i<=NF;++i){if($i==""){printf "null"}else{printf $i} if(i tmpfile.txt && mv tmpfile.txt "$gfile".csv # remove the first 3 rows of csv, wich are instructions to the client and headers sed -i '1,3d' "$gfile".csv #removespaces sed -i 's/ //g' "$gfile".csv # remove hyphens sed -i 's/-//g' "$gfile".csv } function scrape { echo "" > $tfile #loop through the tenants that have valid apt and cell numbers where physical extension field is no. cat "$gfile".csv | awk -F , '($1 != "null") && ($4 != "null") && ($5 == "no") {print $1, $2, $3, $4, $5}' | while read apt first last cell phys do echo -e '' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e ' ' >> $tfile echo -e '' >> $tfile echo -e '\n' >> $tfile done #cat "$gfile".csv | awk -F , '($1 != "null") && ($4 != "null") && ($5 == "yes") {print $1, $2, $3, $4, $5}' | while read apt first last cell phys #do # add code here when hardwired phones are installed. See "Follow Me" in Freeswitch wiki #done echo "" >> $tfile /usr/local/freeswitch/bin/fs_cli -x reloadxml } ####### remountrw cp $tfile to "$tfile".bk rm $tfile prepwork scrape remountro