Category Archives: Shell Script

Delete snapshots older than 7 days

To avoid running out of disk space in our test environment, we developed a plan to regularly execute shell scripts to clean up unnecessary snapshots. #!/bin/bash week=`date –date=’7 days ago’ +’%Y%m%d’` echo “list_snapshots” | /home/webuser/hbase-1.2.9/bin/hbase shell | grep “pattern ” … Continue reading

Posted in HBase, Shell Script | Comments Off on Delete snapshots older than 7 days

[Shelll Script] check tomcat status

!/bin/bash tomcat7=$(ps -ef | grep tomcat | wc -l) echo ${#tomcat7} if [ ${#tomcat7} -gt 0 ]; then printf “tomcat is running\n” else printf “tomcat is not running\n” fi

Posted in Linux, Shell Script, Tomcat | Leave a comment

Redirect stdout to logFile in shell script

exec > >(tee -i logfile.txt) source: stackoverflow: redirect COPY of stdout to log file from within bash script itself

Posted in Shell Script | Leave a comment

find unused files and delete them

find /var/log/radius/radacct -type f -name “reply*” -mtime +60 -exec rm -rf {} \; -mtime N — more than N days without being edited -exec CMD {} \; — comands, {} means the files which be found.

Posted in Linux, Shell Script | Leave a comment

Parse JSON string via command line

Ref.:How to parse JSON string via command line on Linux Ubuntu: apt-get install jq Mac: brew install jq

Posted in Shell Script | Leave a comment

Redir 每日記錄回報

#!/bin/sh /bin/cat /var/log/syslog* | grep -a “ubuntu redir” | grep “`date –date=yesterday +%b %e`” > /root/diary.log /bin/zcat /var/log/syslog.*.gz | grep -a “ubuntu redir” | grep “`date –date=yesterday +%b %e`” >> /root/diary.log if [ -s /root/diary.log ] ; then /bin/cat /root/diary.log| … Continue reading

Posted in Linux, Shell Script | Leave a comment

Shell Script Dialog

Dialog 預設設定通常在個人Home目錄下的檔案”.dialogrc” 可使用指令 “dialog –create-rc ~/.dialogrc” 產生 因為預設底色是青色,結束後會有色塊殘留,所以建議將screen_color調整為黑色 也可在 dialog 指令執行前先指定使用哪一個設定檔案進行dialog “export DIALOGRC=${path}/dialog.installer” 記得離開前把DIALOGRC清空就好 下面是將常用的dialogrc寫成function dialog_msgbox() { #$1 => msgbox的類別{no clear, clear, clear & exit}, $2 => 前視窗的文字說明, $3 => 顯示的資訊文字 case $1 in 0) dialog –backtitle “${backtitle}” –title “$2” … Continue reading

Posted in Shell Script | Leave a comment

Shell Script 計算字元

cowman@ubuntu:~$ string=”0123 56 89″; echo “length: ${#strstring ing}” length: 10

Posted in Linux, Shell Script | Leave a comment