Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- whoexpires=$(mysql -N -u'automail' -p'pass' -e'USE playground; SELECT id, email, soon_expires, last_email_date FROM users WHERE soon_expires = 1;')
- users=$(xargs -n4 <<< "$whoexpires")
- today=date + '%Y-%m-%d'
- datecond=$(( today - 60 * 60 * 24 * 45 ))
- createArray() {
- #no clue here...
- }
- setLastEmail() {
- mysql -N -u'automail' -p'pass' -e'USE playground; UPDATE last_email_date FROM users SET last_email_date = $today WHERE id = $1;'
- }
- arrays=0
- while IFS= read -r line
- do
- createArray line
- (( arrays++ ))
- done <<< "$users"
- for i in $arrays
- do
- local id=$generatedarray*[0]
- local email=$generatedarray*[1]
- local last_email_date=$generatedarray*[3]
- # send email only if last sent was 45 days ago
- if $last_email_date -ge $datecond ; then
- ssmtp $email < ~/mails/account_expired.txt
- setLastEmail $id
- else
- echo "Skipping $generatedarray*[1] - no need to spam his inbox." > automail.log
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement