Advertisement
jonwitts

iSAMS Student Photos for Moodle Bash

Feb 10th, 2015
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # call our PHP script to update photo file locations
  4. date >>  /var/www/scripts-logs/student-photo-import.log 2>&1
  5. echo "Calling user-picture-locations.php script now!" >> /var/www/scripts-logs/student-photo-import.log 2>&1
  6. echo "-----------------------------------------------" >> /var/www/scripts-logs/student-photo-import.log 2>&1
  7. php user-picture-locations.php >> /var/www/scripts-logs/student-photo-import.log 2>&1
  8.  
  9. # remove all jpg files from import directory and cd into it
  10. rm ./photoimports/*.jpg;
  11. cd ./photoimports;
  12.  
  13. # Save our old delimter and set it to a comma
  14. OIFS=$IFS;
  15. IFS=",";
  16.  
  17. # define our input file
  18. csvfile="../user-picture-locations.csv";
  19.  
  20. date >>  /var/www/scripts-logs/student-photo-import.log 2>&1
  21. echo "Connecting via smbclient" >>  /var/www/scripts-logs/student-photo-import.log 2>&1
  22.  
  23. # load our input file a run through a line at a time
  24. cat $csvfile | while read line; do
  25.   # load each line into an array
  26.   locationsArray=($line);
  27.   # fetech our files with smbclient
  28.   smbclient //iSAMS-IIS-Server/e$ -U AD-User-With-Read-Access-to-Share%ReallyLongComplexPasswordWithoutAnySpecialCharactersInIt -W YourDomainName -c "${locationsArray[0]}"  >> /var/www/scripts-logs/student-photo-import.log 2>&1
  29.   # rename our files to match Moodle usernames
  30.   echo "Renaming ${locationsArray[1]} to ${locationsArray[2]}"  >> /var/www/scripts-logs/student-photo-import.log 2>&1
  31.   mv ${locationsArray[1]} ${locationsArray[2]}  >> /var/www/scripts-logs/student-photo-import.log 2>&1
  32. done
  33.  
  34. echo "Done copying and renaming files" >> /var/www/scripts-logs/student-photo-import.log 2>&1
  35. echo "-----------------------------------------------" >> /var/www/scripts-logs/student-photo-import.log 2>&1
  36.  
  37. cd ../;
  38.  
  39. # call our PHP script to update photos in Moodle
  40. date >>  /var/www/scripts-logs/student-photo-import.log 2>&1
  41. echo "Calling updatepics.php script now!" >> /var/www/scripts-logs/student-photo-import.log 2>&1
  42. echo "-----------------------------------------------" >> /var/www/scripts-logs/student-photo-import.log 2>&1
  43. php updatepics.php --dir=./photoimports >> /var/www/scripts-logs/student-photo-import.log 2>&1
  44.  
  45. # set IFS back...
  46. IFS=$OIFS;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement