2013年12月14日土曜日

wgetでWebサイトのレスポンスを調査するシェルスクリプト

wgetを利用して複数Webサイトのレスポンスを調査するシェルスクリプトのサンプルです。
今回は試しにキャリア3社のWebサイトのレスポンスを調査してみました。

OS: CentOS 6.4(64-bit)
wget: GNU Wget 1.12 built on linux-gnu.


■シェルスクリプトサンプル
[root@centos64 ~]# cat response.sh
#!/bin/sh
# wgetを利用してWebサイトのレスポンスを調査する。

URL=url.list
LOG=response_`date +%Y%m%d-%H%M`.log
TODAY=`date +%Y-%m-%d`

# url.listの存在チェック
if [ ! -f ${URL} ]; then
    echo "${URL} no such file or directory"
    exit 1
fi

wget -t 2 -P response -o ${LOG} -i ${URL}
rm -rf response

#grep "[0-9]\]$" ${LOG}
#grep -B 3 "404 Not Found" ${LOG}
grep ${TODAY} ${LOG}

exit 0
[root@centos64 ~]#
リトライは2回くらいで十分かと。

■URLリスト
[root@centos64 ~]# cat url.list
https://www.nttdocomo.co.jp/
https://www.nttdocomo.co.jp/product/
https://www.nttdocomo.co.jp/service/
https://www.nttdocomo.co.jp/binary/pdf/corporate/technology/document/pdc/jidoushadenwa.pdf

http://www.kddi.com/
http://www.au.kddi.com/
http://www.kddi.com/corporate/ir/library/annual_report/pdf/kddi_ar2013_j.pdf

http://www.softbank.jp/
http://www.softbank.jp/corp/
http://cdn.softbank.jp/corp/set/data/csr/pdf/csr2013_01.pdf
[root@centos64 ~]#
サイズの大きいPDFファイルへのリンク等を適当に入れています。

■実行結果
[root@centos64 ~]# ./response.sh
--2013-12-14 16:43:37--  https://www.nttdocomo.co.jp/
2013-12-14 16:43:42 (2.11 MB/s) - `response/index.html' へ保存終了 [44553]
--2013-12-14 16:43:42--  https://www.nttdocomo.co.jp/product/
2013-12-14 16:43:42 (2.02 MB/s) - `response/index.html.1' へ保存終了 [76905]
--2013-12-14 16:43:42--  https://www.nttdocomo.co.jp/service/
2013-12-14 16:43:43 (1.03 MB/s) - `response/index.html.2' へ保存終了 [162300]
--2013-12-14 16:43:43--  https://www.nttdocomo.co.jp/binary/pdf/corporate/technology/document/pdc/jidoushadenwa.pdf
2013-12-14 16:43:43 (2.18 MB/s) - `response/jidoushadenwa.pdf' へ保存完了 [733433/733433]
--2013-12-14 16:43:43--  http://www.kddi.com/
2013-12-14 16:43:48 (1023 KB/s) - `response/index.html.3' へ保存終了 [13808]
--2013-12-14 16:43:48--  http://www.au.kddi.com/
2013-12-14 16:43:53 (2.05 MB/s) - `response/index.html.4' へ保存完了 [56991/56991]
--2013-12-14 16:43:53--  http://www.kddi.com/corporate/ir/library/annual_report/pdf/kddi_ar2013_j.pdf
2013-12-14 16:43:55 (4.69 MB/s) - `response/kddi_ar2013_j.pdf' へ保存完了 [8913281/8913281]
--2013-12-14 16:43:55--  http://www.softbank.jp/
2013-12-14 16:44:00 (377 KB/s) - `response/index.html.5' へ保存終了 [43626]
--2013-12-14 16:44:00--  http://www.softbank.jp/corp/
2013-12-14 16:44:00 (460 KB/s) - `response/index.html.6' へ保存完了 [35866/35866]
--2013-12-14 16:44:00--  http://cdn.softbank.jp/corp/set/data/csr/pdf/csr2013_01.pdf
2013-12-14 16:44:07 (2.64 MB/s) - `response/csr2013_01.pdf' へ保存完了 [3378593/3378593]
終了しました --2013-12-14 16:44:07--
[root@centos64 ~]#
※レスポンス結果はその時々で変化します。
※上記はその時の結果であり、何かを保証するものではありません。

この情報が何かのお役にたてれば幸いです。m(_ _)m

2013年10月19日土曜日

複数URLのリンク切れをチェックするシェルスクリプト


ドメインの異なる複数のWebサイトに対してリンク切れが発生していないか
URLのリストに従ってチェックするシェルスクリプトのサンプルです。
wgetの--spiderオプションを利用しています。

OS: CentOS 6.4(64-bit)
wget: GNU Wget 1.12 built on linux-gnu.


■シェルスクリプトサンプル
#!/bin/sh
#######################################################################
# << 機能概要 >>
# URLリストを読み込んでリンク切れチェックするスクリプト
#
# << 変更履歴 >>
# Version  変更日       変更者        変更内容
# --------+------------+-----------+----------------------------------
#     1.0  2013/10/12   tanyao      New
#######################################################################

URL_LIST=url_list.txt
OUTPUT=url_result.txt

# URLリスト存在チェック
if [ ! -e $URL_LIST ]; then
    echo "`date \"+%Y%m%d %H:%M:%S\"` ERROR: $URL_LIST is not exist."
    exit 1
fi

# 出力結果クリア
:> $OUTPUT

# URLリスト読み込み
i=0
while read line
do
    url[$i]="$line"

    # リンク切れチェック結果出力
    wget -nv --spider --timeout 15 -t 1 ${url[$i]} -a $OUTPUT

    i=`expr $i + 1`
done < $URL_LIST

exit 0
url_check.sh というファイル名で保存し、パーミッションを755に変更。

■URLリストファイル準備
[root@centos64 url_check]# head url_list.txt
http://kakaku.com/item/J0000011385/
http://kakaku.com/item/J0000009488/
http://kakaku.com/item/K0000588606/
http://kakaku.com/item/K0000590023/
http://kakaku.com/item/K0000999999/
http://static.panoramio.com/photos/large/94004107.jpg
http://static.panoramio.com/photos/large/94007107.jpg
http://static.panoramio.com/photos/large/9d004108.jpg
http://www.atmarkit.co.jp/ait/articles/1302/05/news222.html
http://topics.jp.msn.com/world/topics.aspx?topicid=1985
url_check.sh と同階層にurl_list.txtを配置する。

■スクリプト実行
url_result.txtが出力される。
[root@centos64 url_check]# ./url_check.sh
[root@centos64 url_check]# head url_result.txt
2013-10-07 00:39:20 URL: http://kakaku.com/item/J0000011385/ 200 OK
2013-10-07 00:39:21 URL: http://kakaku.com/item/J0000009488/ 200 OK
2013-10-07 00:39:21 URL: http://kakaku.com/item/K0000588606/ 200 OK
2013-10-07 00:39:21 URL: http://kakaku.com/item/K0000590023/ 200 OK
http://kakaku.com/item/K0000999999/:
リモートファイルが存在していません -- リンクが壊れています!!!
2013-10-07 00:39:22 URL: http://static.panoramio.com/photos/large/94004107.jpg 200 OK
2013-10-07 00:39:22 URL: http://static.panoramio.com/photos/large/94007107.jpg 200 OK
http://static.panoramio.com/photos/large/9d004108.jpg:
リモートファイルが存在していません -- リンクが壊れています!!!
wgetのバージョンによっては、ステータスコードが200の場合、何も出力されない場合があります。

リンクチェック対象が多いとそれなりに時間がかかります。この情報がお役にたてれば幸いです。

2013年10月10日木曜日

RedHatサブスクリプションの登録方法

OSインストール後にrhn_register のコマンドラインバージョン画面にて
RHEL6のサブスクリプションを登録する手順を中心に説明します。
これを完了するとyumが利用できるようになります。

OS: Red Hat Enterprise Linux 6.4 (64-bit)


■Red Hatログイン再作成

サブスクリプションを購入すると下記のような「Red Hatログイン作成リクエスト」メールメールが送られてくる。
そこに記載されているリンクからRedHatログインを作成する。
お客様は下記のアカウントでRed Hatサブスクリプションを申し込まれています。 お名前 : XXXXX YYYYY CORPORATION アカウント番号: 53***** - *サブスクリプションにアクセスするには、Red Hatログインが必要です。* ログインをまだお持ちでない場合は、以下のリンクをクリックして作成してください: http://www.redhat.com/wapps/ugc/register.html?id=832qwer56789okfiexxxvvvcccfffhn.redhat.com - セキュリティ上の理由により、上記のリンクが機能するのは1回だけで、2013年xx月xx日 以降にこのリンクは無効になります。
ログインID、パスワード、メールアドレス等必要情報を登録する。
インストール番号は、今先作成したRed Hatログインで
サブスクリプション > インベントリ > コントラクト 102xxxxx > サブスクリプション 29xxxxx
上記ページに表示されている。

■rhn_register コマンドラインバージョン画面

OSインストール後、ssh等でログインし、rootアカウントにスイッチ。


以降は基本的に画面の説明に従って進む。




Tabキーで項目間を移動、スペースキーで選択。って画面下に表示されていますね…。


RedHatログインとパスワードは先ほどRHNで登録した内容を設定。




プロファイル名にはサーバのホスト名等を設定。














以上でサブスクリプションの登録は完了です。
何かのお役にたてれば幸いです。画面キャプチャ張り付けまくった甲斐がありますように・・・。

2013年7月12日金曜日

LinuxのFTPサーバ(vsftpd)にrootで接続

通常FTPでサーバに接続する場合は、root以外のユーザを使用しますが、時にはそれが
めんどくさい、いえ、rootで接続する必要がある場合もあるのでその手順をまとめます。
AWS上のEC2(Amazon Linux)にvsftpdをインストールしてrootで接続する手順です。

【FTPサーバ】
OS: Amazon Linux AMI 2013.03(64-bit)
vsftpd: 2.2.2


■AMIバージョン確認

[ec2-user@ip-10-77-30-93 ~]$ cat /etc/system-release Amazon Linux AMI release 2013.03 [ec2-user@ip-10-77-30-93 ~]$

■rootパスワード設定

[ec2-user@ip-10-77-30-93 ~]$ cat /etc/system-release Amazon Linux AMI release 2013.03 [ec2-user@ip-10-77-30-93 ~]$ sudo passwd Changing password for user root. New password: BAD PASSWORD: it is based on a dictionary word Retype new password: passwd: all authentication tokens updated successfully. [ec2-user@ip-10-77-30-93 ~]$ su - Password: [root@ip-10-77-30-93 ~]#

■vsftpd インストール

[root@ip-10-77-30-93 ~]# yum install vsftpd (中略) ======================================================================= Package Arch Version Repository Size ======================================================================= Installing: vsftpd x86_64 2.2.2-11.9.amzn1 amzn-main 163 k Transaction Summary ======================================================================= Install 1 Package(s) Total download size: 163 k Installed size: 331 k Is this ok [y/N]: y Downloading Packages: vsftpd-2.2.2-11.9.amzn1.x86_64.rpm | 163 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : vsftpd-2.2.2-11.9.amzn1.x86_64 1/1 Verifying : vsftpd-2.2.2-11.9.amzn1.x86_64 1/1 Installed: vsftpd.x86_64 0:2.2.2-11.9.amzn1 Complete! [root@ip-10-77-30-93 ~]#

■バージョン確認

[root@ip-10-77-30-93 ~]# vsftpd -v vsftpd: version 2.2.2 [root@ip-10-77-30-93 ~]#

■vsftpd.confのuserlist_enable=YESとなっていることを確認

[root@ctc-dev-cms ~]# grep -n userlist_enable /etc/vsftpd/vsftpd.conf 118:userlist_enable=YES [root@ctc-dev-cms ~]#

■user_listのrootをコメントアウト

[root@ctc-dev-cms ~]# cp -p /etc/vsftpd/user_list /etc/vsftpd/user_list.org [root@ctc-dev-cms ~]# vi /etc/vsftpd/user_list [root@ctc-dev-cms ~]# diff /etc/vsftpd/user_list /etc/vsftpd/user_list.org 7c7 < #root --- > root [root@ctc-dev-cms ~]#

■ftpusersのrootをコメントアウト

[root@ctc-dev-cms ~]# cp -p /etc/vsftpd/ftpusers /etc/vsftpd/ftpusers.org [root@ctc-dev-cms ~]# vi /etc/vsftpd/ftpusers [root@ctc-dev-cms ~]# diff /etc/vsftpd/ftpusers /etc/vsftpd/ftpusers.org 2c2 < #root --- > root [root@ctc-dev-cms ~]#

■vsftpd起動(再起動)

[root@ip-10-77-30-93 ~]# /etc/init.d/vsftpd start Starting vsftpd for vsftpd: [ OK ] [root@ip-10-77-30-93 ~]#

■FFFTPで接続

※FFFTPの設定で 接続 > 拡張 > 「PASVモードを使う(V)」のチェックを外すところがポイント。



rootでのFTP接続成功!!

こちらの情報が何かのお役に立ちましたら幸いです。 m(_ _)m

2013年4月6日土曜日

Webmin ログイン画面のカスタマイズ


Webmin標準のログイン画面のメッセージの変更やIPアドレスを非表示にする手順をまとめます。

OS: CentOS 6.4(64-bit)
Webmin: 1.620


■ログイン画面のメッセージを変更
[root@centos64 ~]# cd /usr/libexec/webmin/lang [root@centos64 lang]# cp -p en en.org [root@centos64 lang]# vi en [root@centos64 lang]# diff en en.org 131,132c131,132 < session_header=Login to Change Password < session_mesg=You must enter a username and password to login to the Webmin server. --- > session_header=Login to Webmin > session_mesg=You must enter a username and password to login to the Webmin server on $1. [root@centos64 lang]#
131行目のsession_headerの値および132行目のsession_mesgの値を修正。

■ログイン画面のボックスのサイズ変更し、リンク追加
[root@centos64 ~]# cd /usr/libexec/webmin/ [root@centos64 webmin]# cp -p session_login.cgi session_login.cgi.org [root@centos64 webmin]# vi session_login.cgi [root@centos64 webmin]# diff session_login.cgi session_login.cgi.org 62c62 < "width=60% class='loginform'", 2); --- > "width=40% class='loginform'", 2); 91,92d90 < print "<br /><a href=\"https://54.249.xxx.xxx:81/re-issued_password.html\" target=\"_blank\">"; < print "<b>Forgot your password?</b></a><br />\n"; [root@centos64 webmin]# [root@centos64 webmin]# head -93 session_login.cgi | tail -4 print &ui_form_end(); print "<br /><a href=\"https://54.249.xxx.xxx:81/re-issued_password.html\" target=\"_blank\">"; print "<b>Forgot your password?</b></a><br />\n"; print "</center>\n"; [root@centos64 webmin]#
リンクの追加は、&ui_form_end()と</center>の間が適当です。
※表示の都合上、一部”<”と”>”に置き換えています。



■ログイン画面確認

Webminの再起動等は不要で変更が即時反映されます。

以上です。何かのお役にたてれば幸いです。