yum -y install perl-CGI

sudo yum -y install perl-CGIで、perl-CGIをinstall

[vagrant@localhost ~]$ sudo yum -y install perl-CGI
– 中略 -
トランザクションを実行しています
インストールしています : perl-CGI-3.51-144.el6.x86_64 1/1
Verifying : perl-CGI-3.51-144.el6.x86_64 1/1

インストール:
perl-CGI.x86_64 0:3.51-144.el6

インストール後、やり直します。

データがcgiに届きました。

#!/usr/bin/perl --
use strict;
use utf8;
use warnings;
use CGI;

my $q = new CGI;
my $param1 = $q->param('name');
my $param2 = $q->param('password');

print "Content-type:text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<h1>Hello World, $param1 password is $param2</h1>";
print "</html>";

うーん、パラメータが付くのが気になるな。。hiddenだと、type=”password”にできないし、困ったな。。

use CGIでinternal server error

form

<!DOCTYPE html>
<meta charset="utf-8">
<style>
#errorMessage {
	color: red;
}
</style>
<form action="/cgi-bin/test.cgi">
<div id="errorMessage"></div>

<label for="name">お名前:</label>
<input name="name" id="name" required><br>
<label for="password">パスワード:</label>
<input type="password" name="password" id="password" required><br>
<label for="passwordConfirm">パスワード(確認):</label>
<input type="password" name="confirm" id="confirm" oninput="CheckPassword(this)"><br>
<input type="submit" value="送信">
</form>
<script>
		function CheckPassword(confirm){
			var input1 = password.value;
			var input2 = confirm.value;

			if (input1 != input2){
				confirm.setCustomValidity("入力値が一致しません");
			} else{
				confirm.setCustomValidity('');
			}
		}
</script>

データ受け取りのcgi

#!/usr/bin/perl --
use strict;
use utf8;
use warnings;
use CGI;

my $q = new CGI;
my $param1 = $q->param('name');
my $param2 = $q->param('password');

print "Content-type:text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<h1>Hello World</h1>";
print "</html>";

view

なんでやねん、て、use CGIをコメントアウトするとinternal server errorが消えているので、おそらくcuse CGIがinstallされていないだけかと。。

[vagrant@localhost ~]$ find `perl -e ‘print “@INC”‘` -name ‘*.pm’ -print | grep CGI

パスワード 入力値の確認 その2

<!DOCTYPE html>
<meta charset="utf-8">
<style>
#errorMessage {
	color: red;
}
</style>
<form>
<div id="errorMessage"></div>

<label for="name">お名前:</label>
<input name="name" id="name" required><br>
<label for="password">パスワード:</label>
<input type="password" name="password" id="password" required><br>
<label for="passwordConfirm">パスワード(確認):</label>
<input type="password" name="confirm" id="confirm" oninput="CheckPassword(this)"><br>
<input type="submit" value="送信">
</form>
<script>
		function CheckPassword(confirm){
			var input1 = password.value;
			var input2 = confirm.value;

			if (input1 != input2){
				confirm.setCustomValidity("入力値が一致しません");
			} else{
				confirm.setCustomValidity('');
			}
		}
</script>

うまくいきました。

oninput=””か、なるほど。

パスワード 入力値の確認

<!DOCTYPE html>
<meta charset="utf-8">
<style>
#errorMessage {
	color: red;
}
</style>
<form>
<div id="errorMessage"></div>

<label for="name">お名前:</label>
<input name="name" id="name" required><br>
<label for="password">パスワード:</label>
<input type="password" name="password" id="password" required><br>
<label for="passwordConfirm">パスワード(確認):</label>
<input type="password" name="passwordConfirm" id="passwordConfirm" required><br>
<input type="submit" value="送信">
</form>
<script>
var form = document.forms[0];
form.onsubmit = function(){
	form.password.setCustomValidity("");

	if(form.password.value != form.passwordConfirm.value){
		form.password.setCustomValidity("パスワードと確認用パスワードが一致しません")
	}
}
form.addEventListener("invalid", function(){
	document.getElementById("errorMessage").innerHTML = "入力値にエラーがあります";
}, false);
</script>

あれ? あれ?
うまくいきませんね。。

「確認」「クリア」「戻る」ボタン

I want to display the “confirmation”, “clear” and “return” buttons within HTML form.
Here is User Interface.

confirm: type=”submit”
clear: type=”reset”
return: type=”button” onclick=”history.back()”

<center>
		<button type="submit">確認</button> <button type="reset">クリア</button> <button type="button" onclick="history.back()">戻る</button>
	</center>

It’s easy than expected.

.travis.yml2

language: ruby
rvm: 1.9.3

env:
  global:
    - RAILS_ENV=document
    - secure: "hogehoge"

branches:
  except: /^(feature|try).*$/

branches:
  only:
    - master
    - develop

before_install:
  - eval `ssh-agent -s`
  - chmod 600 ~/.ssh/config
  - openssl aes-256-cbc -K $encrypted_XXX_key -iv $encrypted_xxx_iv -in .travis/travis_key.enc -out travis_key -d
  - cp travis_key ~/.ssh/
  - chmod 600 ~/.ssh/travis_key
  - ssh-add ~/.ssh/travis_key

after_success: .travis/after_success.sh
after_failure: .travis/after_failure.sh 

なるほどー

.travis.yml

TravisCI flow
1. git clone the repository(where .travis.yml is located) from Github
the option –depth=50 is attached to git clone
2. Move to the cloned repository
3. Get committed code by git checkout
Environment variables written in .travis.yml apply here
4. If you use cache, get cache
5. Specify the version of Ruby to use
6. The one defined in before_install is executed
if you use a cache, it will be added here
7. The one defined in install is executed
8. The one defined in before_script is executed
9. What is defined in script is executed
If the exit code is 0 it is judged as success, otherwise it is judged as failure
10. The one defined in after_success or after_failure is executed.
11. The one defined in after_script is executed

ふむ、工程ごとに分かれたスクリプトを実行するのね。

WARN|ERR|FAIL|CRIT

It is possible to specify up to 8 levels in the error log up to which level errors should be recorded. set to “LogLevel” to specify.

LogLevel to record.
The level that can be set are as follows.

Level Meaning
A serious error that the emerg server can not run.

-Errors: More serious than alert crit
-Crit; Serious error
-Error: Error
-Warn: Warning
-Notice: Notification message
-Info: Server information, information for debug debugging.

egrep i

egrep [option][search string pattern] filename

Search for files with a search string pattern and a command to output matching lines.
Search for [File] with [Search string pattern] and output matching lines.
You can use regular expressions more advanced than grep.

まず適すとファイルを作ります。
yahoo.txt

1	8411	東証1部	(株)みずほフィナンシャルグループ	03/20	175.5	+0.75%	+1.3	106,216,600	掲示板
2	5020	東証1部	JXTGホールディングス(株)	03/20	542.9	+0.37%	+2	42,028,800	掲示板
3	8306	東証1部	(株)三菱UFJフィナンシャル・グループ	03/20	573.3	-0.26%	-1.5	33,412,300	掲示板
4	3765	東証1部	ガンホー・オンライン・エンターテイメント(株)	03/20	405	+5.74%	+22	31,808,200	掲示板
5	4347	東証JQS	ブロードメディア(株)	03/20	94	+9.30%	+8	29,353,800	掲示板
6	4755	東証1部	楽天(株)	03/20	1,011	+4.12%	+40	22,479,800	掲示板
7	9973	東証JQS	(株)小僧寿し	03/20	62	+44.19%	+19	18,652,400	掲示板
8	8604	東証1部	野村ホールディングス(株)	03/20	409.9	-2.24%	-9.4	18,591,800	掲示板
9	3092	東証1部	(株)ZOZO	03/20	2,025	+1.25%	+25	18,435,700	掲示板
10	4565	マザーズ	そーせいグループ(株)	03/20	1,421	+15.91%	+195	18,249,700	掲示板

続いて、egrep -i

[vagrant@localhost tests]$ egrep -i "グループ" yahoo.txt
1       8411    東証1部 (株)みずほフィナンシャルグループ        03/20   175.5  +0.75%   +1.3    106,216,600     掲示板
3       8306    東証1部 (株)三菱UFJフィナンシャル・グループ  03/20   573.3  -0.26%   -1.5    33,412,300      掲示板
10      4565    マザーズ        そーせいグループ(株)    03/20   1,421   +15.91%+195     18,249,700      掲示板

ほう。

shell 文字列長のオプション -n

-n:文字列長が 0 より大なら真

#!/bin/sh

index="hoge"
if [ -n $index ]; then
	echo "文字列長が0より大です"
fi

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
文字列長が0より大です

#!/bin/sh

index=""
if [ -n $index ]; then
	echo "文字列長が0より大です"
fi

[vagrant@localhost tests]$ sed -i ‘s/\r//’ test.sh
[vagrant@localhost tests]$ ./test.sh
文字列長が0より大です

あれええええええええええええええええええ??