Skip to content

Instantly share code, notes, and snippets.

@mintsoft
Created May 19, 2013 22:01
Show Gist options
  • Save mintsoft/5609225 to your computer and use it in GitHub Desktop.
Save mintsoft/5609225 to your computer and use it in GitHub Desktop.
Pipe a command into psql within a loop with a heredoc
#!/usr/bin/perl
$svr="localhost";
$dbname="rob";
for $x (1..10) {
open(CMD, " | psql -h $svr $dbname");
print CMD <<END;
BEGIN TRANSACTION;
INSERT INTO insert_log ("when") VALUES(NOW());
INSERT INTO insert_log ("when") VALUES(NOW() + interval '$x day');
COMMIT;
END
print CMD $heredoc;
close(CMD);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment