Shell Script 計算字元

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

Posted in Linux, Shell Script | Leave a comment

使用GMail SMTP寄信 – ssmtp (CentOS)

  1. yum install ssmtp

  2. vim /etc/ssmtp/ssmtp.conf
    root=username@gmail.com
    mailhub=smtp.gmail.com:587
    RewriteDomain=
    Hostname=username@gmail.com
    UseSTARTTLS=yes
    AuthUser=username@gmail.com
    AuthPass=password
    FromLineOverride=YES
    TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

  3. alternatives –config mta
    選擇 /usr/sbin/sendmail.ssmtp

  4. 檢查目前sendmail方式
    sendmail -V
    sSMTP 2.61 (Not sendmail at all)

  5. 測試
    echo “This is a test” | mail -s “Test” cowman.chiang@gmail.com

Reference
1. After updating sSMTP to version 2.61 I cannot send mail via gmail
2. How To Setup sSMTP on CentOS 5.9

Posted in CentOS | Leave a comment

使用GMail SMTP寄信 – command (CentOS)

近來發現diary log幾乎都收不到了
測試了一下, 發現連手動執行script都失敗
所以想一下就改用GMail SMTP應該比較保險

Reference: 在 Linux 上直接用 Gmail SMTP 寄信

yum install mailx

vim ~/.mailrc
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=username@gmail.com
set smtp-auth-password=password
set from=”username@gmail.com”
set ssl-verify=ignore
set nss-config-dir=/root/.pki/nssdb

set nss-config-dir=/etc/pki/nssdb

}

後續使用
echo ‘信件顯示內容信件顯示內容信件顯示內容’ | mailx -v -A gmail -s “信件標題” 收件者mail

Posted in CentOS | Leave a comment

Gitlab改使用GMail SMTP

  1. 檢查 config/environments/production.rb 檔案,查看
    config.action_mailer.delivery_method = :sendmail
    的註解是否已增加,關閉Gitlab sendmail寄送服務
    config.action_mailer.delivery_method = :sendmail

[註] 使用這一篇 使用GMail SMTP寄信 (Ubuntu) 的方法應該也可以~但是目前會出現
“Mail failure – no recipient addresses”
A message that you sent using the -t command line option contained no
addresses that were not also on the command line, and were therefore
suppressed. This left no recipient addresses, and so no delivery could
be attempted.
的錯誤,所已先改用gitlab直接使用google的smtp

  1. 在 config/environments/production.rb 檔案加入
    config.action_mailer.raise_delivery_errors = true
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.perform_deliveries = true
    config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "你的網站位置",
    :authentication => :plain,
    :user_name => "你的GMAIL帳號",
    :password => "你的GMAIL密碼",
    :enable_starttls_auto => true
    }

  2. 修改config/gitlab.yml檔案,將email_from修改為gmail帳號
    email_from: 你的GMAIL帳號

  3. 重啟gitlab服務
    service gitlab restart

  4. 修改gitlab使用者project權限,測試有沒有成功

Posted in Git, Ubuntu | Leave a comment

使用GMail SMTP寄信 (Ubuntu)

安裝mailx、exim4
apt-get install exim4-daemon-light mailutils

dpkg-reconfigure exim4-config
General type of mail configuration:
│ internet site; mail is sent and received directly using SMTP │
│ mail sent by smarthost; received via SMTP or fetchmail │
│ mail sent by smarthost; no local mail │
│ local delivery only; not on a network │
│ no configuration at this time

System mail name:
cowman.no-ip.org

IP-addresses to listen on for incoming SMTP connections:
127.0.0.1 ; ::1

Other destinations for which mail is accepted:
(null)

Machines to relay mail for:
(null)

IP address or host name of the outgoing smarthost:
smtp.gmail.com::587

Hide local mail name in outgoing mail?
YES NO

Keep number of DNS-queries minimal (Dial-on-Demand)?
YES NO

Delivery method for local mail:
│ mbox format in /var/mail/ │
│ Maildir format in home directory │

Split configuration into small files?
YES NO

Root and postmaster mail recipient:
(null)

vim /etc/exim4/passwd.client 加入
*:帳號:密碼

測試寄信
echo "This is a test." | mail -s Testing cowman.chiang@gmail.com

ssh登入時寄發通知信件
echo 'ALERT - Shell Access (Git) on:' date who | mailx -A gmail -s "Alert: Shell Access from who | cut -d'(' -f2 | cut -d')' -f1" cowman.chiang@gmail.com > /dev/null 2>&1

Posted in Ubuntu | Leave a comment

SSH 登入時寄發通知信件

vim ~/.bashrc

echo ‘ALERT – Shell Access (WP) on:’ date who | mailx -A gmail -s “Alert: Shell Access from who | cut -d'(' -f2 | cut -d')' -f1” cowman.chiang@gmail.com > /dev/null 2>&1

搭配 使用GMail SMTP寄信 這一篇進行
其中 > /dev/null 2>&1 是不想讓使用者一登入就出現有warning issue的事件…還沒想到怎麼解決~先讓錯誤訊息消失…

Reference : How to Get Root and User SSH Login Email Alerts

Posted in Linux | Leave a comment

CentOS 快速安裝 Nginx with RTMP module

之前裝在Ubuntu的那一篇 一樣
都是沒有設定stat的部分, 需要在另外修改

大致上跟Ubuntu的方式都相同
只是要注意的為 init script 可不可正常進行
測試的範例中是修改 nginx.conf 將 pid 那一行給取消註腳

pid        logs/nginx.pid;
#!/bin/sh
yum groupinstall 'Development Tools' -y
yum install pcre pcre-devel openssl-devel libxslt-devel -y
cd /tmp
wget http://nginx.org/download/nginx-1.7.3.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
tar -zxvf nginx-1.7.3.tar.gz
yum install unzip -y
unzip master.zip
cd nginx-1.7.3/
./configure --with-http_ssl_module --with-http_xslt_module --add-module=../nginx-rtmp-module-master
make
make install

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

echo " " >> /usr/local/nginx/conf/nginx.conf
echo "rtmp {" >> /usr/local/nginx/conf/nginx.conf
echo "        server {"  >> /usr/local/nginx/conf/nginx.conf
echo "                listen 1935;" >> /usr/local/nginx/conf/nginx.conf
echo "                chunk_size 4096;" >> /usr/local/nginx/conf/nginx.conf
echo " " >> /usr/local/nginx/conf/nginx.conf
echo "                application live {" >> /usr/local/nginx/conf/nginx.conf
echo "                        live on;" >> /usr/local/nginx/conf/nginx.conf
echo "                        record off;" >> /usr/local/nginx/conf/nginx.conf
echo "                        #allow publish 127.0.0.1;" >> /usr/local/nginx/conf/nginx.conf
echo "                        #deny publish all;" >> /usr/local/nginx/conf/nginx.conf
echo "                        #allow play 127.0.0.1;" >> /usr/local/nginx/conf/nginx.conf
echo "                        #deny play all;" >> /usr/local/nginx/conf/nginx.conf
echo "                }" >> /usr/local/nginx/conf/nginx.conf
echo "        }" >> /usr/local/nginx/conf/nginx.conf
echo "}" >> /usr/local/nginx/conf/nginx.conf

# 這邊直接使用放在網站上的檔案
# 請複製 http://wiki.nginx.org/RedHatNginxInitScript 中的檔案至 nignx 中
cd /etc/init.d/
vim nginx
chmod +x nginx
service nginx start
# service nginx start|stop|reload
Posted in CentOS, Nginx, RTMP | Leave a comment

Cacti Debug : 圖出不來

檢查
Management => Graph Management => 找到出不來的圖 => Turn On Graph Debug Mode
看看rrdtool的log資訊為何

Posted in Cacti | Leave a comment

Cacti 自訂 Script php

  1. 記得php檔案最後return值格式
  2. 新增 Data Input Methods <== 呼叫script php方法
    Input Type => Script – Script Server (PHP)
    Input String => /scripts/[php檔名] [php內使用的function名稱] <hostname> [參數值]
    Input Fields => hostname
    — Special Type Code ==> hostname
    Output Fields => 欄位名稱

  3. 新增Data Templates
    Data Template => Name => [Template的名稱] //VMware ESXi – HW Information – Processor_Temperature
    Data Source =>
    — Name => |host_description| – [Data Source的名稱] //|host_description| – VMware ESXi – HW Information – Processor_Temperature
    — Data Input Method => [選擇使用的Data Input Method]
    — Step => [多久執行一次]
    — Data Source Active => 勾選
    Data Source Item,這是最麻煩的,一開始編輯完先按Save,在按New,會出現一個ds的tab,修改為新增的資訊,再按save,再按new….
    — Internal Data Source Name => [data source的name] //ESXi_CPU_Temp_1 <== 會出現在tab的名稱
    — Output Field => [選擇要使用的欄位名稱] //這邊會自動抓取Data Input Method設定的Output欄位資訊

  4. 新增 Graph Templates
    通常一個來源資料在Graph Item會有四個項目
    (1) 畫線
    — Color => 選喜歡的
    — Graph Item Type => LINE1
    — Consolidation Function => Average (可以依據需求選擇)
    — Text Format => 欄位名稱 (或是要顯示的文字)
    (2) 文字顯示目前值
    — Graph Item Type => GPRINT
    — Consolidation Function => LAST
    — Text Format => Current:
    (3) 文字顯示最大值
    — Graph Item Type => GPRINT
    — Consolidation Function => MAX
    — Text Format => MAX:
    (4) 文字顯示最小值
    — Graph Item Type => GPRINT
    — Consolidation Function => MIN
    — Text Format => MIN:

這時後可以發現 Graph Item Input 有自動增加了
下面的欄位參考如下
Template => Name => [Template的名稱]
Graph Template =>
— Title => |host_description| – [圖的名稱]
— Vertical Label => [欄位值單位標示]

然後新增Device的Graph,就ok了…..

Posted in Cacti | Leave a comment

VMware esxi command : esxcli

  1. esxcli hardware ipmi sdr list //取得感應器資訊

  2. esxcli system process stats load get //取得目前負載狀況

參考

Posted in VMware | Leave a comment