The type VII U-Boat used at the time had a single, unprotected 88mm deck gun. The type IX had a larger 105mm gun. Their primary use was to sink unescorted merchant ships because torpedoes are expensive. While the range is listed as 12km, I have serious doubts they could hit even a large industrial target at half that range at night from the pitching deck of a U-Boat.
While 88mm (3.5") sounds big (it is for a WWII tank) by naval standards it is a pea-shooter and unlikely to do enough damage to be worth risking the boat. Your typical coastal defense gun will be 8" to 16", often guns stripped from old battleships.
And risk the boat they would! They would have to be on the surface, probably at night (the US left the lights on), in sight of the shore, with a large number of sailors on the deck, firing a cannon. They would be visible and vulnerable and slow to dive in shallow water. If spotted, any number of patrol boats and airplanes could arrive and harass them.
What would they shoot at that was worth the risk and they were able to hit and damage? Fuel storage tanks are the only thing that comes to mind. But a handful of U-Boats would not be able to make a dent in the US fuel reserves. That was the end result of many of Germany's plans to attack the US, too risky, too expensive, too little result.
Finally, there were very few U-Boats attacking the US. The first wave was just five Type IX's, which were designed to operate so far from home. The third wave in the Caribbean was only 11. I don't have data for the second, but the Germans never had enough U-Boats.
The Japanese did bombard the US West Coast with little result. They shot at fuel tanks, a fort and a lighthouse. The Japanese had the advantage of a much larger (140mm) gun, and they couldn't hit anything.
What about firing at civilian targets and causing panic? While we have the image of a crazed Hitler ordering downtown Manhattan bombarded, that sort of thing happened much later in the war when he'd fired or killed most of his good commanders and had nothing but party sycophants left. At this stage in the war the German military high command upheld at least the veneer of honor. Germany was winning and they could afford to fight fair. My speculation is this would not have gone over well with Dönitz or the U-Boat captains and crews. It may seem strange to draw a line between firing on civilians in a city and firing on civilians in a boat, but my speculation is they would have.
In the end, the goal was not to harm the US, the goal was to prevent it from projecting power to Europe. They were doing that just fine sinking ships, and the US was doing a fine job letting them.