2

I am missing something below. I keep getting unexpected end of file. What is it?

function lock_inactive_accounts {
    echo "Locking inactive accounts or accounts that haven't logged in during the past 35 days."
    echo " "
    echo "The following accounts have been locked: "
    su - postgres -c "psql database" << EOF
      UPDATE users SET has_locked_account = true WHERE DATE_PART('days', now() - last_successful_login) > 35;
      SELECT name from users where has_locked_account = 't';
        EOF
}

lock_inactive_accounts
2
  • For your own convenience you can consider running problematic snippets like this through shellcheck to get instant feedback on many common problems (including this one) Commented Dec 19, 2013 at 22:57
  • shellcheck, awesome. I never knew about this! Thanks. Commented Dec 23, 2013 at 16:24

1 Answer 1

2

I believe the terminating EOF should be at the beginning of the line for here document to work:

su - postgres -c "psql database" <<EOF
  UPDATE users SET has_locked_account = true WHERE DATE_PART('days', now() - last_successful_login) > 35;
  SELECT name from users where has_locked_account = 't';
EOF
Sign up to request clarification or add additional context in comments.

3 Comments

I tried that, but doesn't seem to make a difference within a function.
I'm pretty certain this is correct regardless. Maybe << EOF. Or the tab-friendly syntax, which I vaguely recollect being <<-EOF or something to that order.
I just checked by copying your (not mine) code above, putting it into a script (no sharp-bang), making sure EOF is starting at column 1, and running (in Linux) and it does work: Locking inactive accounts or accounts that haven't logged in during the past 35 days. The following accounts have been locked: su: must be run from a terminal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.