Categories
- FFMpeg (5)
- Libav (1)
- Google (3)
- iBeacon (1)
- LDAP (3)
- Me (2)
- Network (11)
- OS (149)
- RTMP (4)
- SIP (1)
- Kamailio (1)
- SNMP (1)
- VMware (20)
- VCP考試 (1)
- 伺服器 網站服務 (105)
- 名詞解釋 (4)
- 專案管理 (1)
- 工具軟體 (50)
- Adobe (1)
- FMS (1)
- Cloudera (1)
- Docker (1)
- Eclipse (4)
- Intellij (2)
- OBS (2)
- Office (10)
- Excel (4)
- PowerPoint (5)
- Postman (1)
- Splunk (13)
- Virtualbox (2)
- Visual Studio (2)
- 文字編輯器 (10)
- Sublime Text 2 (6)
- Sublime Text 3 (3)
- Vim (3)
- 連線工具 (1)
- Xshell (1)
- Adobe (1)
- 程式語言 (79)
- CSS (2)
- HTML (2)
- iOS (1)
- Java (30)
- JavaScript (5)
- jQuery (4)
- jsTree (2)
- JSP (3)
- PHP (16)
- Python (7)
- Ruby (1)
- sed (1)
- Shell Script (8)
- Windows Bash Script (1)
- XML (1)
- 資料庫 (37)
- FFMpeg (5)
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/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 " | \ while read CMD; do filename=($CMD) # echo $filename date=`echo $filename | awk -F "_" '{print $2}'` # echo "${filename#*_}" # echo $date # echo ${date:0:8} if [ "${date:0:8}" -lt $week ] then echo "delete_snapshot '$filename'" | /home/webuser/hbase-1.2.9/bin/hbase shell fi done |
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
1 |
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 每日記錄回報
1 2 3 4 5 6 7 |
#!/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| mail -s "Redir Log -- `date --date=yesterday +%b %e`" user@mail.address fi |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
dialog_msgbox() { #$1 => msgbox的類別{no clear, clear, clear & exit}, $2 => 前視窗的文字說明, $3 => 顯示的資訊文字 case $1 in 0) dialog --backtitle "${backtitle}" --title "$2" --msgbox "n${3}" 9 50;; 1) dialog --backtitle "${backtitle}" --title "$2" --clear --msgbox "n${3}" 9 50;; 2) dialog --backtitle "${backtitle}" --title "$2" --clear --msgbox "n${3}" 9 50 export DIALOGRC= exit 1;; esac } dialog_infobox() { #$1 => 前視窗的文字說明, $2 => 顯示的資訊文字 dialog --backtitle "${backtitle}" --title "${1}" --infobox "${2}" 5 50 sleep 1 } dialog_inputbox() { #$1 => 前視窗的文字說明, $2 => 顯示的資訊文字, $3 => 預設值 exec 3>&1 inputtext=$(dialog --backtitle "${backtitle}" --title "${1}" --inputbox "${2}" 10 60 ${3} 2>&1 1>&3) exec 3>&- } dialog_yesno() { #$1 => 前視窗的文字說明, $2 => 顯示的資訊文字 dialog --backtitle "${backtitle}" --title "${1}" --yesno "${2}" 7 60 return $? } dialog_passwdbox() { #$1 => 前視窗的文字說明, $2 => 顯示的資訊文字 exec 3>&1 inputtext=$(dialog --backtitle "${backtitle}" --title "${1}" --insecure --clear --passwordbox "${2}" 10 60 2>&1 1>&3) exec 3>&- } |
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