Generally, it's better to write fewer SQL commands that return more rows of information in the result set, then use a program that reads that data.
You might try this kind of query:
select DATE(DATE_MODIFIED), CART_ID, USER_ID
where DATE_MODIFIED >= CURDATE() - INTERVAL 60 DAY
and DATE_MODIFIED < CURDATE()
ORDER BY DATE(DATE_MODIFIED)
This will get you a result set with 60 days' data in it, with the first column giving the date. Then your Java program can work through the result set and pull out each day's information.
The idea of running thousands of queries from a shell script will, as you know, work. But it is inherently slow. And, it is difficult to parallelize. You're much better off running one query, especially if the thousands of queries can be reduced to one.