Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. whoexpires=$(mysql -N -u'automail' -p'pass' -e'USE playground; SELECT id, email, soon_expires, last_email_date FROM users WHERE soon_expires = 1;')
  2. users=$(xargs -n4 <<< "$whoexpires")
  3. today=date + '%Y-%m-%d'
  4. datecond=$(( today - 60 * 60 * 24 * 45 ))
  5.  
  6. createArray() {
  7. #no clue here...
  8. }
  9.  
  10. setLastEmail() {
  11. mysql -N -u'automail' -p'pass' -e'USE playground; UPDATE last_email_date FROM users SET last_email_date = $today WHERE id = $1;'
  12. }
  13.  
  14. arrays=0
  15. while IFS= read -r line
  16. do
  17. createArray line
  18. (( arrays++ ))
  19. done <<< "$users"
  20.  
  21. for i in $arrays
  22. do
  23. local id=$generatedarray*[0]
  24. local email=$generatedarray*[1]
  25. local last_email_date=$generatedarray*[3]
  26. # send email only if last sent was 45 days ago
  27. if $last_email_date -ge $datecond ; then
  28. ssmtp $email < ~/mails/account_expired.txt
  29. setLastEmail $id
  30. else
  31. echo "Skipping $generatedarray*[1] - no need to spam his inbox." > automail.log
  32. fi
  33. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement