0

I have a file that contains one SQL command per line and I pipe it to the mysql client.

I would like to know at which line it fails (when it fails) to be able to continue without re-processing the already-processed lines.

cat my_file | magic_cmd | mysql --params
shprogram
  • 118
  • 2
  • 8
moechofe
  • 3
  • 1
  • 1
    What is `magic_cmd` supposed to be? How do you actually run this? Do you really `cat` the file and pipe into `mysql`? Can't you just loop over the file instead? – terdon Nov 02 '20 at 16:54
  • I expect your mysql client program to print line number and error when executing a file. If not run a bash while loop and print anything. Also I think you cannot place any command in that position and catch safely at which line the next program after the pipe exited. You can catch when you tried to write into the pipe and it was broken. – thanasisp Nov 02 '20 at 20:24

1 Answers1

0

Let magic_cmd keep a sequence number, and send a "select $seqno;" to mysql before each command. Direct the output of mysql to a file that you can examine for errors afterwards.

Gerard H. Pille
  • 2,350
  • 9
  • 13