The process of downloading, sanity checking, and processing the membership list is somewhat complex. Therefore it's been broken into two shell scripts and a PHP/Drupal script (suckit.sh, sanity.sh, and syncit.php, respectively), all controlled by the master script file "update-members.sh" (below).
#/bin/bash # # DJM, 2012-03-13 # # Master shell script to control daily processing of the EAA-supplied membership list. # Invoked via webmaster's cron table entry, viz: # # m h dom mon dow command # 37 4 * * * (cd ~/membership-list; bash ./syncit.sh) # # Note: The minute value of 37 is arbitrary, chosen to help ensure that not # everything happens at the top of the hour. # Convenience var export D7=/usr/local/share/drupal7 # Get to our base directory cd ~webmaster/membership-list # Attempt to download the current file bash ./suckit.sh # Quit if the child script failed if [ $? != 0 ] then exit fi # Sanity check the file bash ./sanity.sh # Quit if the child script failed if [ $? != 0 ] then exit fi # Invoke the Drupal script to process each line in the file # !!! drush -r $D7 -l www.iac.org scr syncit.php < membership-list.csv # Quit if the child script failed if [ $? != 0 ] then exit fi # Invoke the Drupal script to set user roles to lapsed or current, as appropriate drush -r $D7 -l www.iac.org scr lapsed.php # Copy the just-processed file to the archive directory cp membership-list.csv archive/members.`date '+%Y-%m-%dT%H:%M:%S'` # Finally, remove any files in the archive that are more than 30 days old # There are more concise ways to code this, except this method won't cause # rm to throw a "missing operands" error if there are no files to delete. find archive -name 'members.*' -mtime +30 | while read f do rm "$f" done echo "Daily run of update-members.sh complete."