This is my crontab:crontab -e30 5 * * * sh /home/donato/Documents/pg_bak.shEvery day at 5:30am I want to execute a shell script I created called pg_bak.sh.This is the contents of the shell script:#!/bin/bashPG_USER=donatoDATABASE=mydbSERVER=216.58.219.174DIR=$HOME/pg_bakDATE=$(date +%m_%d_%y)FILE=$DATABASE_$DATE# pass @ .pgpassPG_BAK_NOW () {  pg_dump -h $SERVER -U $PG_USER $DATABASE -f $FILE.sql  }echo Ready to dump to $FILE >> $HOME/pg_status cd $DIRif [ -f $FILE ];then  rm $FILE  PG_BAK_NOW else  PG_BAK_NOWfiI want to backup the sql file on my local machine at ~/pg_bak, NOT on the remote server. In other words, I do not want to backup the file on the remote server. Will the pg_dump command be running in the context of the computer I am running it from or from the remote server?
backup file locally in shell script
shell script;postgresql
Simply usepg_dump -h $SERVER -U $PG_USER $DATABASE > $FILE.sql to output the result of the command to the local machine.  You might want to pipe it through gzip or similar, first, to obtain a smaller dump. Since I'm already here, a couple of other suggestions:30 5 * * * /home/donato/Documents/pg_bak.shYou don't need to invoke sh to run your script, just give it the owner execution bit.And the whole chunk of code in the script immediately after the echo can be changed to:cd $DIRrm $FILE 2>/dev/nullPG_BAK_NOW In fact, since now you're invoking pg_dump only once, there's no need to wrap it in a function -- just call it directly.