Embed MySQL in shell script -
how insert data table using mysql using shell script? maximum number of records change based on parameter. should use for
loop in shell script embedded mysql?
i have attached attempt below, , not inserting record. can review , correct me please?
#!/bin/bash mysql -u root -p"" << eof use school; eof echo -n "enter numebr of students enroll" read echo -n "enter marks" read marks (( i=1; i‹= 10; i++ )) for((sub=1; sub‹= 8; sub++ )) echo "enter subject name" read subject if [$marks=y | y<=100 | y>=0] << eof insert students('id$i',$subject,$marks) eof echo record inserted
you can use mysql
command in shell script execute query shown below:
$./script.sh 10 limit=$1 for(i=1;i<limit;i++){ //input value $v1 //input value $v2 //input value $v3 mysql --host=database_host_name --user=mysql_user --password=mysql_user_password your_db_name << eof insert your_table (col1,col2,col3) values('$v1','$v2','$v3'); eof }
note
don't forgot quote variable single quotes (for varchar field)
Comments
Post a Comment