Runing crontab jobs for postgres user ?

Posted on 2013-11-28
Last Modified: 2014-01-17
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 !
Question by:Shakthi777
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Expert Comment

ID: 39683328
Did you run your script at linux shell directly and successfully ?

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

/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


Expert Comment

ID: 39684216
maybe this help you:

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


sudo su postgres -c "your commend  ... "
LVL 13

Assisted Solution

duncanb7 earned 250 total points
ID: 39684234

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

LVL 19

Accepted Solution

simon3270 earned 250 total points
ID: 39688639
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:
exec /folder/script1 -m srv1:5432 -s srv2:5432 -b /usr/lib/postgresql/9.2/bin

Open in new window


Author Closing Comment

ID: 39787918
tnx !

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question