0

I'm new with Makefile. I need to automate create user for postgres terminal.

I tried this example and it did not work for me:

createuser:
    @echo "$(OK_COLOR)==> create user$(NO_COLOR)"
    @psql mydbdevelopmentname
    @create user myusername;
    @/q
    @echo "$(OK_COLOR)==> Done$(NO_COLOR)"

Neither @create user myusername; nor @/q works.

When I ran make createuser and exit manually with \q from postgres terminal, I receive this error:

/bin/sh: create: command not found
make: *** [createuser] Error 127

1 Answer 1

3

When debugging makefiles, the @ modifier is unhelpful, as it no longer shows those commands before executing them.

I suspect that you actually wanted to pass create user myusername to your psql line, but you wrote it as a separate command. You need to make sure that psql sees it:

psql -c "create user myusername" mydbdevelopmentname

Don't forget to declare your target as a dependency of .PHONY.

I'll note in passing that Make is generally a poor choice to use as a scripting language - it's much better for making targets from their dependencies, as it's designed for. This kind of thing is more suited to a language such as Bash or Python.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm getting different error now psql: FATAL: role "create user myusername" does not exist make: *** [createuser] Error 2
Mixed it up with MySQL - I meant -c, not -e (as the man page would have shown you if you'd bothered).

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.