I have a sh script with which I connect to postgres DB and execute a psql command. The script is as shown below:

/opt/postgres/9.2/bin/psql pcwh  -U  pcwhuser << EOF 
 \i /opt/emms/emsam/tmp/tmp1438861364196.psql 

When I try to run this sh file I get an error "file not found". If I execute these statements from command line manually it works, but I need them to work this from script as well.

  • How are you trying to run this script?
    – larsks
    Commented Aug 12, 2015 at 13:34
  • sh <filename>.sh from command line Commented Aug 12, 2015 at 13:43

1 Answer 1


User should be database user. Who has credential to access pgsql database.
Confirm it using su - <dbuser>

Then run script cause in your script \i /opt/emms/emsam only can run user who has permission to access DB.

  • I have executed them manually as pcwhuser from CLI so it works.its only I need to do this through script. thank you Commented Aug 12, 2015 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .