Here is my issue. I have a set of SQL database queries that I am triggering using a shell script and a corresponding batch file with .sql extension. Some of my queries require some manual user input (As per request), which I have had no luck implementing in my script.
As of now, I take in the user input as a date through the shell script:
echo "Please specify the date in yyyy-mm-dd format: 'input;"
read input
mysql -u user -ppass < batch_file.sql
I would like to pass the variable $input to the batch file.
The batch file with the sql queries being executed looks something like this:
select count(*) as count from subscriptions
where date_add(optin_date, interval 1 year) between "$input"
and date(curdate())
and active = 1
and stype = "domain";
Where "$input" is the variable passed down from the shell script.
Any ideas would bee appreciated, thank you.
Try doing this using a here-doc in a script :
Another solution if you can’t use the first solution for any reason :
Better use something like
%%PATTERN%%instead of$inputin SQL file for substitution if you prefer the second solution.