Sure,
@jata, here is the original post. I am not strong with the Bourne shell, and there are probably a million ways to write this script better.
I've modified the clean-dbs.sh script slightly since then to generate the output, provide some additional metrics, and cleaned up the cron assignment in init-start. I'll provide a console-only output and a file output version of the clean-dbs script below so you can take whichever you like more.
I updated the /jffs/scripts/init-start script (you may have to create one if you don't already have it), and created a script in /jffs/scripts/clean-dbs.sh.
init-start
Code:
#!/bin/sh
### Cron job to delete conn_diag .db entries every minute
cru a cleanConnDiagDbs "* * * * * /bin/sh /jffs/scripts/clean-dbs.sh"
clean-dbs.sh (output to console only - output is only useful for manual runs of the script):
Code:
#!/bin/sh
echo ""
echo "********************************************************************************"
echo "***** Running Clean Dbs *****"
echo "********************************************************************************"
echo ""
### WIFI detect
echo "wifi_detect.db count before delete"
/usr/sbin/sqlite3 /tmp/.diag/wifi_detect.db 'select count() FROM DATA_INFO;'
/usr/sbin/sqlite3 /tmp/.diag/wifi_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "wifi_detect.db count after delete"
/usr/sbin/sqlite3 /tmp/.diag/wifi_detect.db 'select count() FROM DATA_INFO;'
### STA info
echo "stainfo.db count before delete"
/usr/sbin/sqlite3 /tmp/.diag/stainfo.db 'select count() FROM DATA_INFO;'
/usr/sbin/sqlite3 /tmp/.diag/stainfo.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "stainfo.db count after delete"
/usr/sbin/sqlite3 /tmp/.diag/stainfo.db 'select count() FROM DATA_INFO;'
### ETH detect
echo "eth_detect.db count before delete"
/usr/sbin/sqlite3 /tmp/.diag/eth_detect.db 'select count() FROM DATA_INFO;'
/usr/sbin/sqlite3 /tmp/.diag/eth_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "eth_detect.db count after delete"
/usr/sbin/sqlite3 /tmp/.diag/eth_detect.db 'select count() FROM DATA_INFO;'
### NET detect
echo "net_detect.db count before delete"
/usr/sbin/sqlite3 /tmp/.diag/net_detect.db 'select count() FROM DATA_INFO;'
/usr/sbin/sqlite3 /tmp/.diag/net_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "net_detect.db count after delete"
/usr/sbin/sqlite3 /tmp/.diag/net_detect.db 'select count() FROM DATA_INFO;'
### SYS detect
echo "sys_detect.db count before delete"
/usr/sbin/sqlite3 /tmp/.diag/sys_detect.db 'select count() FROM DATA_INFO;'
/usr/sbin/sqlite3 /tmp/.diag/sys_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "sys_detect.db count after delete"
/usr/sbin/sqlite3 /tmp/.diag/sys_detect.db 'select count() FROM DATA_INFO;'
echo " File Sizes:"
ls -lh /tmp/.diag
echo ""
echo " Free:"
free
echo ""
echo "********************************************************************************"
echo "********************************************************************************"
echo ""
Or, you can run the clean-dbs.sh script with output to a file (say in your /jffs or /mnt directory) - but you'll want to monitor its size and respond appropriately; there's no sense in fixing a RAM issue only to cause a storage issue (replace the LOG_FILE assignment in the second line with the path your want to save the log to):
Code:
#!/bin/sh
LOG_FILE="<path-to-your-desired-output-file-location>"
echo "" >> $LOG_FILE
echo "********************************************************************************" >> $LOG_FILE
echo "***** Running Clean Dbs *****" >> $LOG_FILE
echo "********************************************************************************" >> $LOG_FILE
echo ""
### WIFI detect
echo "wifi_detect.db count before delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/wifi_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/wifi_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "wifi_detect.db count after delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/wifi_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
### STA info
echo "stainfo.db count before delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/stainfo.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/stainfo.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "stainfo.db count after delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/stainfo.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
### ETH detect
echo "eth_detect.db count before delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/eth_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/eth_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "eth_detect.db count after delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/eth_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
### NET detect
echo "net_detect.db count before delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/net_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/net_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "net_detect.db count after delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/net_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
### SYS detect
echo "sys_detect.db count before delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/sys_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/sys_detect.db 'delete from DATA_INFO WHERE strftime("%s","now") - data_time > 300;'
echo "sys_detect.db count after delete" >> $LOG_FILE
/usr/sbin/sqlite3 /tmp/.diag/sys_detect.db 'select count() FROM DATA_INFO;' >> $LOG_FILE
echo " File Sizes:" >> $LOG_FILE
ls -lh /tmp/.diag >> $LOG_FILE
echo "" >> $LOG_FILE
echo " Free:" >> $LOG_FILE
free >> $LOG_FILE
echo "" >> $LOG_FILE
echo "********************************************************************************" >> $LOG_FILE
echo "********************************************************************************" >> $LOG_FILE
echo "" >> $LOG_FILE