database - Accepting user input in MYSQL? Shell Script / Batch File -
database - Accepting user input in MYSQL? Shell Script / Batch File -
here issue. have set of sql database queries triggering using shell script , corresponding batch file .sql extension. of queries require manual user input (as per request), have had no luck implementing in script.
as of now, take in user input date through shell script:
echo "please specify date in yyyy-mm-dd format: 'input;" read input mysql -u user -ppass < batch_file.sql
i pass variable $input
batch file.
the batch file sql queries beingness executed looks this:
select count(*) count subscriptions date_add(optin_date, interval 1 year) between "$input" , date(curdate()) , active = 1 , stype = "domain";
where "$input"
variable passed downwards shell script.
any ideas bee appreciated, give thanks you.
try doing using here-doc in script :
#!/bin/sh echo "please specify date in yyyy-mm-dd format: 'input;" read input mysql -u user -ppass <<eof select count(*) count subscriptions date_add(optin_date, interval 1 year) between "$input" , date(curdate()) , active = 1 , stype = "domain"; eof
another solution if can't utilize first solution reason :
echo "please specify date in yyyy-mm-dd format: 'input;" read input sed -i "s/\"\$input\"/$input/g" batch_file.sql mysql -u user -ppass < batch_file.sql
better utilize %%pattern%%
instead of $input
in sql file substitution if prefer sec solution.
mysql database shell user-input
Comments
Post a Comment