I'm setting up a cron job to do some routine maintenance for a postgresql database. The script is as follows:
#!/bin/sh
dbname="dbname"
username="postgres"
psql -d $dbname -U $username << EOF
delete from links_link where submitted_on > now() - interval'4 days';
EOF
However when run via crontab, this fails because I have not provided the password for the user postgres
.
My question is: how do I include the password for the user postgres in the shell script? That will get me up and running fast. Secondly, how do I improve security by not having to explicitly add a password in my script? If anyone's set up this kind of a thing before, their experience is most welcome. Thanks in advance.