Get Shortcode output to database for static post_content

The code you have currently is going to create a new post rather than update the post where the shortcode is in use. In order to update the post, you’ll need to
include its ID (see the documentation).

Here’s how you can update your code to include the ID:

global $post; // Use the global $post object for the current post.
$args = array(
    'ID'           => $post->ID,
    'post_content' => $content,
);
wp_insert_post( $args ); // Update the current post with the $content.

return $content;

I also removed the $wpdb usage because you don’t need to access the database directly; the wp_insert_post function will take care of it for you.


Note: I’ve focused this answer on just the part of the code that I think is failing you. I’m not convinced the shortcode approach is an ideal solution (for instance, it might be better to write a simple plugin that loops through your files and creates all the post entries one time). However, I hope this answer helps you achieve your goal right now; there’s always the opportunity to optimize as needed.