定时在数据库表中插入数据—shell脚本
实现:在每个时间段的00分,15分,30分,45分插入一条数据
上图是在db主机上执行成功的代码
在vscode中编写的代码
代码都附上(两个代码应保持一致),防止有差异!!!
#!/bin/sh
hostName="localhost"
port="3306"
userName="root"
passWord="1cmszx#YZSSY"
dataBase="oms"
int=999
while :
do
timeStamp=`date +%s`
timeStamp=`date +'%Y-%m-%d %H:%M:00' -d@${timeStamp}`
minute=`date +%M`
if [$minute == 00 -o $minute == 15 -o $minute == 30 -o $minute == 45]
then
hostname="host"$int
insertSqlHnds="insert into d_url_statistics_hnds(
mo_id,
time_stamp,
CallNotify,
CallNotifyResp,
CallControl,
CallControlResp,
AINotifySend,
AIControlRecv)
values(
$int,
\"$timeStamp\",
$(($RANDOM%50+1)),
$(($RANDOM%50+1)),
$(($RANDOM%50+1)),
$(($RANDOM%50+1)),
$(($RANDOM%50+1)),
$(($RANDOM%50+1)));"
/home/ebsql/mysql/bin/mysql -u${userName} -p${passWord} ${dataBase} -e "${insertSqlHnds}"
fi
sleep 1m
done
说明:
- int=999对应的是mo_id中的网元id值>
- 除了time_stamp,其他均生成随机数
- 如果需要在后台执行此脚本,需要在脚本所在路径下执行 nohup ./wxshell.sh &
如图
- 如果需要手动执行脚本,sh wxshell.sh
如图: