★RubyOnRails用として仮想サーバをCentOSで構築。 ⇒MySQLはOSバンドルを利用予定。 ⇒RubyおよびRailsは最新版をインストール予定。 ■OSインストール時のパッケージ選択 ----------------------------------------------------------- 【デスクトップ環境】 ■ GNOMEデスクトップ環境 □ KDE(Kデスクトップ環境) 【アプリケーション】 □ Emacs □ Office/生産性 ■ エディタ ■ グラフィカルインターネット ■ グラフィクス □ ゲームと娯楽 ■ サウンドとビデオ □ テキストベースのインターネット □ 技術系と科学系 □ 著作権と発行 【開発】 □ GNOMEソフトウェア開発 ■ Java開発 □ KDEソフトウェア開発 □ Ruby □ Xソフトウェア開発 ■ レガシーなソフトウェアの開発 ■ 開発ツール ■ 開発ライブラリ 【サーバー】 □ DNSネームサーバー ■ FTPサーバー ■ MySQLデータベース □ PostgreSQLデータベース ■ Webサーバー ■ Windowsファイルサーバー ■ サーバー設定ツール □ ニュースサーバー □ ネットワークサーバー □ メールサーバー □ レガシーなネットワークサーバー □ 印刷サポート 【ベースシステム】 ■ Java ■ OpenFabrics Enterprise ディストリビューション ■ X Window System ■ システムツール □ ダイヤルアップネットワークサポート ■ ベース ■ レガシーなソフトウェアのサポート ■ 管理ツール 【仮想化】 □ KVM □ 仮想化 【クラスタリング】 □ クラスタリング 【クラスタストレージ】 □ クラスタストレージ 【言語】 ■ 日本語のサポート
2011年9月17日土曜日
CentOS5.7インストールパッケージ
2011年6月28日火曜日
cookie検証
[root@tanyao0b cgi-bin]# cat login.cgi
#!/usr/bin/perl
#フォームからの受け取りをデコードする
&dec;
#クッキーの読み出し
&splt;
#入室用のパスワード
$passw = '0123';
#入力されたパスが正しければ
if ($forminh{'pass'} eq $passw) { &site_form; }
#cookieのパスが正しければ
elsif ($COOKIE{'ckpas'} eq $passw) { &site_cookie; }
# 初期アクセス
print <<"HTML";
Content-type: text/html
統合監視システムへようこそ!
HTML
exit;
#入力されたパスが正しければ表示するサイトのサブルーチン
sub site_form
{
#クッキーの書き出し
print <<"HTML";
Content-type: text/html
Set-Cookie: ckpas=$forminh{'pass'}; expires=Tue, 1-Jan-2030 00:00:00 GMT; path=/cgi-bin/;
HTML
print <<"HTML";
Content-type: text/html
Get from COOKIE: $ENV{'HTTP_COOKIE'}
Get from FORM: $forminh{'pass'}
下記リンクをクリックするとこのページをリロードします。
login.cgi
HTML exit; } #cookieのパスが正しければ表示するサイトのサブルーチン sub site_cookie { print <<"HTML"; Content-type: text/html
Get from COOKIE: $ENV{'HTTP_COOKIE'}
Get from FORM: $forminh{'pass'}
ログアウトはこちら
HTML exit; } #フォームからの値をデコードするサブルーチン sub dec { #フォームからデータを受け取り変数へ入れる read(STDIN, $formin, $ENV{'CONTENT_LENGTH'}); # + 記号を半角スペースに戻す $formin =~ tr/+/ /; #URLエンコードデータをデコード $formin =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; @indata = split (/&/,$formin); #受け取ったデータを&で区切り、配列へ foreach $tmp (@indata) #フォームの要素分(配列分)以下の処理を繰り返す { ($name,$value) = split (/=/,$tmp); # =記号で区切り、名前 と 値 に分ける $forminh{$name} = $value; #区切った名前を付けた連想配列に値を入れる } } #クッキー読み出し用のサブルーチン sub splt { @cookdata = split(/;/,$ENV{'HTTP_COOKIE'}); #クッキーを配列に foreach $tmp (@cookdata) #クッキーデータの有る間処理をする { ($youso,$atai) = split(/=/,$tmp); #要素名と値に区切る $youso =~ s/ //; #要素間のスペース除去 $COOKIE{$youso} = $atai; #要素名の連想配列に値を入れる } } [root@tanyao0b cgi-bin]# cat logout.cgi #!/usr/bin/perl #クッキーの読み出し &splt; #入室用のパスワード $passw = '0123'; #cookieのパスが正しければ if ($COOKIE{'ckpas'} eq $passw) { &site_cookie; } # 初期アクセス print <<"HTML"; Content-type: text/html
認証画面はこちら
HTML exit; #cookieのパスが正しければ表示するサイトのサブルーチン sub site_cookie { #クッキーの書き出し print <<"HTML"; Content-type: text/html Set-Cookie: ckpas= ; expires=Tue, 1-Jan-2020 00:00:00 GMT; path=/cgi-bin/; HTML print <<"HTML"; Content-type: text/html
Get from COOKIE: $ENV{'HTTP_COOKIE'}
Get from FORM: $forminh{'pass'}
Delete Password from Cookie !!
ログイン画面はlogin.cgi
HTML exit; } #クッキー読み出し用のサブルーチン sub splt { @cookdata = split(/;/,$ENV{'HTTP_COOKIE'}); #クッキーを配列に foreach $tmp (@cookdata) #クッキーデータの有る間処理をする { ($youso,$atai) = split(/=/,$tmp); #要素名と値に区切る $youso =~ s/ //; #要素間のスペース除去 $COOKIE{$youso} = $atai; #要素名の連想配列に値を入れる } }
2011年6月14日火曜日
smbセッションキャッシュクリア
--------------------------------------------------
同じユーザーによる、サーバーまたは共有リソースへの複数のユーザー名での複数の接続は許可されません。
サーバーまたは共有リソースへの以前の接続をすべて切断してから、再試行してください。
--------------------------------------------------
上記のようなメッセージが表示され、smb領域のディレクトリにアクセスできない場合
コマンドプロンプトから解消可能。
C:\Documents and Settings\Administrator>net use
新しい接続は記憶されます。
ステータス ローカル名 リモート名 ネットワーク名
-------------------------------------------------------------------------------
OK \\192.168.188.54\files_bk Microsoft Windows Network
\\TSCLIENT\C Microsoft Terminal Services
\\TSCLIENT\D Microsoft Terminal Services
\\TSCLIENT\S Microsoft Terminal Services
コマンドは正常に終了しました。
C:\Documents and Settings\Administrator>net use \\192.168.188.54\files_bk /delete
\\192.168.188.54\files_bk が削除されました。
同じユーザーによる、サーバーまたは共有リソースへの複数のユーザー名での複数の接続は許可されません。
サーバーまたは共有リソースへの以前の接続をすべて切断してから、再試行してください。
--------------------------------------------------
上記のようなメッセージが表示され、smb領域のディレクトリにアクセスできない場合
コマンドプロンプトから解消可能。
C:\Documents and Settings\Administrator>net use
新しい接続は記憶されます。
ステータス ローカル名 リモート名 ネットワーク名
-------------------------------------------------------------------------------
OK \\192.168.188.54\files_bk Microsoft Windows Network
\\TSCLIENT\C Microsoft Terminal Services
\\TSCLIENT\D Microsoft Terminal Services
\\TSCLIENT\S Microsoft Terminal Services
コマンドは正常に終了しました。
C:\Documents and Settings\Administrator>net use \\192.168.188.54\files_bk /delete
\\192.168.188.54\files_bk が削除されました。
2011年6月7日火曜日
Linux OSユーザ一括作成シェルスクリプト
通常OSユーザを作成する場合は、useraddコマンドおよびpasswdコマンドを手動で打ち、 一人ひとり作成していきますが、ユーザ数が多くなるとちょっと厄介、ぶっちゃけめんどいです。 今回紹介するスクリプトはユーザ情報がリスト化されたファイルを読み込んで一括でユーザを 作成することができます。 ただし、ユーザが所属するグループを事前に作成しておく必要があります。
■グループを事前に作成
[root@tanyao script]# /usr/sbin/groupadd -g 5000 public
■ユーザリストを準備
[root@tanyao script]# cat mk_user.list # name:password:uid:gid:comment:home_directory:login_shell:sub_gid user01:secret01:5001:5000:::/bin/bash user02:secret02:5002:5000:::/bin/bash user03:secret03:5003:5000:::/bin/bash #user04:secret04:5004:5000:::/bin/bash user05:secret05:5005:5000:::/bin/bash [root@tanyao script]#※ /etc/passwd ファイルのフォーマットに合わせてみた。つもり。
■ユーザ一括作成スクリプト(mk_user.sh)
[root@tanyao script]# cat mk_user.sh
#!/bin/sh
# mk_user.listに記述されたユーザを一括で作成します。
# 行頭に"#"がある行はコメント行とみなします。
# 既に存在しているユーザを作成しようとするとスキップされます。
# 事前にグループを作成ください。
# rootユーザで実行してください。
USERLIST=./mk_user.list
if [ ! -f ${USERLIST} ]; then
echo "${USERLIST} no such file or directory"
exit 1
fi
grep -v \^# ${USERLIST} | while read line
do
name="`echo ${line} | cut -d ":" -f1`"
passwd="`echo ${line} | cut -d ":" -f2`"
uid="`echo ${line} | cut -d ":" -f3`"
gid="`echo ${line} | cut -d ":" -f4`"
comment="`echo ${line} | cut -d ":" -f5`"
homedir="`echo ${line} | cut -d ":" -f6`"
loginsh="`echo ${line} | cut -d ":" -f7`"
subgid="`echo ${line} | cut -d ":" -f8`"
# サブグループがない場合
if [[ ${subgid} = "" ]]; then
/usr/sbin/useradd -u ${uid} -g ${gid} -c "${comment}" ${name} || continue
# サブグループがある場合
else
/usr/sbin/useradd -u ${uid} -g ${gid} -G ${subgid} -c "${comment}" ${name} || continue
fi
echo ${name}:${passwd} | chpasswd
echo "Making ${name} succeeded."
done
exit 0
[root@tanyao script]#
[root@tanyao script]# chmod 755 mk_user.sh
■ユーザ作成
[root@tanyao script]# ./mk_user.sh Making user01 succeeded. Making user02 succeeded. Making user03 succeeded. Making user05 succeeded. [root@tanyao script]#
■確認
[root@tanyao script]# su - user01 [user01@tanyao ~]$ su - user02 Password: [user02@tanyao ~]$ id uid=5002(user02) gid=5000(public) groups=5000(public) [user02@tanyao ~]$ pwd /home/user02 [user02@tanyao ~]$
■ユーザ削除コマンド(参考)
[root@tanyao script]# userdel -r user05 [root@tanyao script]# id user05 id: user05: No such user [root@tanyao script]#
◆ユーザ作成コマンドオプション確認
[root@tanyao script]# useradd --help
Usage: useradd [options] LOGIN
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
[root@tanyao script]#
◆ユーザ編集コマンドオプション確認
[root@tanyao script]# usermod --help
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
him/her from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user new SELinux user mapping for the user account
[root@tanyao script]#
◆ユーザ削除コマンドオプション確認
[root@tanyao script]# userdel --help
Usage: userdel [options] LOGIN
Options:
-f, --force force removal of files,
even if not owned by user
-h, --help display this help message and exit
-r, --remove remove home directory and mail spool
-Z, --selinux-user remove SELinux user from SELinux user mapping
[root@tanyao script]#
この情報がお役に立ちましたら、いえ、ご寄付はいりません。
サイト継続のご協力を賜りたく存じます。 m(_ _)m
2011年6月2日木曜日
シェルスクリプトサンプル:ログファイル等のアーカイブ
独自開発したアプリケーションのログ等でローテート処理が考慮されていない場合、 ログファイルが増殖し続け、気づいた時にはエライことになっていたなんてことは 誰しもあるはずです。 古くなってきたログファイルを洗い出して圧縮し、さらに一定期間が過ぎると自動削除 するシェルスクリプトを作成しcrontabに登録しておけば、ディスク使用率アラートで 夜中に起こされて対応することはなくなるはずです。
■シェルスクリプトサンプル
#!/bin/sh
# 指定日数より前のファイルを圧縮し、さらに指定日数より古いアーカイブファイルを削除
ARCHIVE_DAYS=10
DELETE_DAYS=60
TARGET_DIR=/root/scripts/logs
OUTPUT=${TARGET_DIR}/`date +%Y%m%d-%H%M`_ArchiveFiles.tar.gz
# 対象ディレクトリへ移動
cd ${TARGET_DIR}
# 圧縮するファイル(拡張子は、.logまたは.txt)のリストを作成
find . -mtime +${ARCHIVE_DAYS} -iregex ".*\.log$\|.*\.txt$" > ${TARGET_DIR}/file.list
# 圧縮対象ファイルが存在するかのチェック
num_line=`cat ${TARGET_DIR}/file.list | wc -l`
if [ ${num_line} -gt 0 ]; then
# リストに従ってtar.gzファイルを作成
tar -zcf ${OUTPUT} -T ${TARGET_DIR}/file.list
# リストに従って元ファイルを削除
for i in `cat ${TARGET_DIR}/file.list`
do
rm -rf ${i}
done
else
echo "ERROR: More than ${ARCHIVE_DAYS} days before the file does not exist !!"
fi
# 指定日数より古いアーカイブファイルを削除
find . -mtime +${DELETE_DAYS} -regex ".*\.tar.gz$" | xargs rm -rf
# リストファイルを削除
# rm -rf ${TARGET_DIR}/file.list
exit 0
こちらの情報が何かのお役に立てましたら幸いです。サイト継続のご協力ありがとうございます。m(_ _)m
登録:
投稿 (Atom)