[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2432
  • Last Modified:

Runing crontab jobs for postgres user ?

Hi Experts,

I need to run some script over my Postgres database by postgres user. So, I have set a cron tab to execute it for every 5 minutes.

*/5 * * * * /folder/script1 -m srv1:5432 -s srv2:5432 -b /usr/lib/postgresql/9.2/bin

Open in new window


script1=the file containing my script

But its not running. I can't root's crontab since it's not allowed in Postgres service.

Can you kindly help me on this and thanks a lot for your time !
0
Shakthi777
Asked:
Shakthi777
2 Solutions
 
duncanb7Commented:
Did you run your script at linux shell directly and successfully ?

If yes, maybe you need to add it in your script

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/usr/bin:/opt/usr/sbin:/usr/local/bin:/usr/local/sbin;
/yourscriptlocation;"   which is just example only

and it might also need to do  " chmod 755 yourscript"

Hope understand your question completely, if not , please point it out

Duncan
0
 
gwnetCommented:
Hi,
maybe this help you:

su postgres -c " your command eq. bash script "

or

sudo su postgres -c "your commend  ... "
0
 
duncanb7Commented:
Shakthi777,

Be reminded, output all stuff including error/warning  generated from script to
a file, post_error.log by the following cron-job setting that will help
to debug your issue in post_error.log

*/5 * * * * /folder/script1 -m srv1:5432 -s srv2:5432 -b /usr/lib/postgresql/9.2/bin >post_error.log


Duncan
0
 
simon3270Commented:
Also, some crontabs have a command length limit - yours (particularly if the script isn't actually in the quite short /folder/script1 J) might be too long.  Try having a wrapper script called, say, /folder/script2 whcich you call with no arguments, and that contains just:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/folder
exec /folder/script1 -m srv1:5432 -s srv2:5432 -b /usr/lib/postgresql/9.2/bin

Open in new window

0
 
Shakthi777Author Commented:
tnx !
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now