Shell Script to Insert rows in loop
I am running this script to connect to the MySQL DB and achieve the following goal.
1. Run the script for a set period of time
2. Run the Script for a set number of iterations with in the that time
3. Generate a unique value to be inserted in a primary key column in the format of say (concat('AKS',YYYYMMDDHHMMSS,(Dynamic 4 digit Number)) E.g. AKS201607131924161001
#!/bin/sh
echo "Start: " $(date +%s)
secs=10 #setting variable
SECONDS=0 # resetting SECONDS to zero
sleep secs && echo "End: " $(date +%s) && kill $$ & #kill process by set time
while ((SECONDS < $secs)) # Starting a loop
do
for ((a=1; a <= 2000 ; a++)) # For unique value to be inserted into table
do
echo "use emp_db;"
echo "INSERT INTO tb_name VALUES ('$a','abc');"
sleep 0
done | mysql -h{Host}-u{username} -p{pswd} -P3306
done
In the above script
1. though the process is killed after set time, the loop still runs and 2000 inserts are made.
2. If the above issue is with for loop, I need help in achieving point 2 & 3 of Goal.
Subject
Written By
Posted
Shell Script to Insert rows in loop
July 13, 2016 10:45PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.