title: Automating pg_basebackup command for recovery using cron and script
body: <p>I have a 2 node system running pacemaker, corosync and postgresql 9.4. I am carrying out pgsql replication using virtual IP and am able to successfully recover a downed machine using manual commands. Now to automate stuff, I want to run the following commands in a script to get my recovered master back on cluster.</p>
  
  <pre><code>`#su -postgres
   $rm -rf /var/lib/pgsql/9.4/data/*     //To delete old data files
   $pg_basebackup -h 192.XX.XX.XX -U postgres -D /var/lib/pgsql/9.4/data   -X stream -P   // To recover the latest data from standby PC running latest entries
   $rm /var/lib/pgsql/tmp/PGSQL.lock
   $exit     //exit from postgresql shell
   #pcs resource cleanup msPostgresql`
  </code></pre>
  
  <p>Now when i run these commands as a script, it hangs after the first command itself i.e. su -postgres and the cursor blinks at bash$ syntax without inserting the commands down below.
  I want to automate this process using cron but the script itself is not working for me. Can someone help me out here.</p>
  
  <p>Regards</p>