in reply to Postgresql output to file

If this is all you want to do, you don't need Perl, you can just use psql -c.

psql -U postgres -d dbase -c "SELECT * FROM logs_column WHERE logged_in > NOW()::timestamp - interval '24hour';"

Replies are listed 'Best First'.
Re^2: Postgresql output to file
by mikebailey (Novice) on Sep 05, 2024 at 15:05 UTC

    You are correct. And I can run that with the -o /home/user/date.txt Works well if I run it manually. But, I need it to run as a cron job every night at 23:59, and add the date as the filename. ie...09012024.txt 09022024.txt 09032024.txt

      I need it to run as a cron job every night at 23:59, and add the date as the filename.

      That's easy with a shell script. Replace -o /home/user/date.txt with -o "/home/user/$(date '+%m%d%Y').txt". Replace the format string passed to the date command with '+%Y%m%d' to get easily sortable file names instead of that M/D/Y mess.

      (Yes, I prefer using perl over shell, but sometimes, the shell is just more efficient.)

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)