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より大です

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

ERROR 1068 (42000): Multiple primary key defined

ERROR 1068 (42000): Multiple primary key defined
複合primary keyで書こうとするとエラーになった。

create table hoge(
	submit_no int not null,
	seq_no int not null,
	report_file_name varchar(128),
	create_userid char(20) not null,
	create_date date not null,
	update_userid char(20),
	update_date date,
	primary key(submit_ms_no, seq_no)	
);

mysql> describe hoge;
+———————-+————–+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+———————-+————–+——+—–+———+——-+
| submit_no | int(11) | NO | PRI | NULL | |
| seq_no | int(11) | NO | PRI | NULL | |
| report_img_file_name | varchar(128) | YES | | NULL | |
| create_userid | char(20) | NO | | NULL | |
| create_date | date | NO | | NULL | |
| update_userid | char(20) | YES | | NULL | |
| update_date | date | YES | | NULL | |
+———————-+————–+——+—–+———+——-+
7 rows in set (0.00 sec)

なるほど。。create文がそもそも違うのね。

MySQLで複数のPrimary Key

一つのテーブルで複数のprimary keyって設定できるの?

submit_noとseq_noでprimary keyを設定するとします。

create table rep_image_info(
	submit_no int not null primary key,
	seq_no int not null primary key,
	report varchar(128),
	create_user char(20),
	create_date date,
	update_user char(20),
	update_date date	
);

この場合、submit_noとseq_noの組み合わせに対して主キーを持つようです。なるほどにゃー
よって、二つでだけでなく、三つ、四つのprimary keyもあるわけですね。

SLA

SLA is an abbreviation of Service Level Agreement, which is an agreement on the level of service (definition, scope, content, achievement goals, etc.) established between the provider of the service and its users. This is a statement to the extent that the service provider can guarantee the quality to the contractor.

SLAs are often used mainly for communication services, cloud services, rental servers, etc. We define service definition and guarantee items such as communication speed and upper limit of use stop time, and if the service quality falls below the guarantee value of SLA, reduction of charge will be performed.

ELB access log

ELBでアクセスログが取得できる。

2014-03-07T07:25:38.285777Z elber 130.0.237.XX:37522 172.31.4.218:80 0.000066 0.00105 0.000037 404 404 0 570 "GET http://54.249.27.XX:80/actus4/ HTTP/1.1"
2014-03-07T07:26:43.731149Z elber 77.50.22.XXX:53477 172.31.4.218:80 0.000053 0.000866 0.000053 200 200 0 10 "GET http://54.249.27.XX:80/ HTTP/1.0"
2014-03-07T07:26:44.410747Z elber 77.50.22.XXX:53656 172.31.4.218:80 0.000052 0.000853 0.000039 404 404 0 168 "GET http://54.249.27.XX:80/foltia/ HTTP/1.0"
2014-03-07T07:26:45.084730Z elber 77.50.22.XXX:53839 172.31.4.218:80 0.000061 0.000874 0.000035 404 404 0 168 "GET http://54.249.27.XX:80/epgrec/do-record.sh HTTP/1.0"
2014-03-07T07:28:12.386207Z elber 189.206.75.XX:64289 172.31.4.218:80 0.000062 0.000924 0.000035 404 404 0 168 "GET http://54.249.27.XX:80/manager/html HTTP/1.1"

問題は、項目。

timestamp
The time accessed by the Client. UTC time, recorded in ISO 8601 format.
2014-02-15T23: 39: 43. 945958 Z

Name of ELB
ELB Name: test-loadbalancer

Client
Port Client IP address and port number
192.168.131.39.2817

Backend
port IP address and port number of the instance to which communication was distributed by ELB. This will tell you which server it was assigned to 10.0.0.0:80

request_processing_time
The time between the ELB receiving a request from the client and sending the request to the instance
0.000073

backend_processing_time
The time it takes for the ELB to send a request to an instance and the instance returns a response.
0.001048

response_processing_time
The time from when the ELB receives a response from an instance to when it returns a response to the client.
0.000057

elb_status_code
response status code.
200

backend_status_code
Response status code of the instance to which the ELB sent the request.
200

received_bytes
Size of received request (bytes)
0

sent_bytes
Size of sent request (bytes)
29

request
request from a client
“GET http://www.example.com:80/HTTP/1.1”

User Agent perspective

How to investigate user agent?
As an example, the user agent for IE9 is described as follows.

Mozilla / 5.0 (compatible;MSIE 9.0; Windows NT 6.1; Trident/5.0)

Application name
It corresponds to the “Mozilla” part. It is used in the sense that it has the function of the type of browser or its application.

Application Version
In the “5.0” part after Mozilla, it indicates the version of the application.

Platform token
It corresponds to the “Windows NT 6.1” part. It will be the display about OS.

Version Token
It corresponds to the part of “MISE 9.0”.Displaying browser version.

Compatibility Flags
It corresponds to the “Compatible” part. It shows the compatibility with Internet Explore.

Rendering engine
It corresponds to the part of “Trident/5.0”. Shows software that causes the browser to display the requested content.

Internet Explore
ver.11

Mozilla / 5.0 (Windows NT 6.3; ARM; Trident / 7.0; Touch; MALNJS; rv: 11.0) like Gecko

ver.10

Mozilla / 5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW 64; Trident / 6.0)

Chrome

Mozilla / 5.0 (Windows NT 5.1) AppleWebKit / 535.11 (KHTML, like Gecko) Chrome / 17.0.963.79 Safari / 535.11

Firefox

Mozilla / 5.0 (Windows NT 6.1; rv: 11.0) Gecko / 20100101 Firefox / 11.0

Safari

Mozilla / 5.0 (Macintosh; U; Intel Mac OS X; en-jp) AppleWebKit / 523.12 (KHTML, like Gecko) Version / 3.0.4 Safari / 523.12

Android

Mozilla / 5.0 (Linux; Android 4.4.2; 302KC Build / 101.0.2c00) AppleWebKit / 537.36 (KHTML, like Gecko) Version / 4.0 Chrome / 30.0.0.0 Mobile Safari / 537.36 YJApp-ANDROID jp.co.yahoo.android. ybrowser / 1.7.5

なるほど、内容よく見ると、どのブラウザか一発でわかりますね。まあ、一般的にユーザーエージェントは偽装されるのであまり意味ないかもしれませんが。そういえば、IPって偽装できるんでしょうか??? Chrome Extensionで、Hotspot Shieldを使えば偽装できるようですが。。

ELB http 460

What is HTTP 460 on ELB
The load balancer received a request from a client, but the client closed the connection with the load balancer before the idle timeout expired.

Check if the client timeout period is longer than the load balancer idle timeout period. Before the client timeout period expires, make sure that target returns a response to the client, or if the client supports it, increase the client timeout period to match the load balancer idle timeout.

301 redirect and 302 redirect

The 301 redirect is “permanent redirect” and “permanent transfer”, while the 302 redirect is “temporary redirect” and “temporary transfer”.

Consider that a URL set to 301 redirect will not appear in the index. However, the 301 redirect takes over the information of the transfer source (old URL) to the transfer destination (new URL).

Amazon S3のAWS署名バーション2の廃止

S3の署名バージョン2が廃止になる。

– 以前の AWS リージョンの一部では、Amazon S3 で署名バージョン 4 と署名バージョン 2 がサポート。ただし、署名バージョン 2 は廃止され、署名バージョン 2 の最終サポートは 2019 年 6 月 24 日に終了
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/UsingAWSSDK.html#UsingAWSSDK-sig2-deprecation

2016年5月以前にリリースされた AWS SDK を使用する場合、次の表に示すように、署名バージョン 4 のリクエストが必要になることがある
AWS CLI

$ aws configure set default.s3.signature_version s3v4
$ aws configure set profile.your_profile_name.s3.signature_version s3v4

Java SDK

System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "true");
-Dcom.amazonaws.services.s3.enableV4

JavaScript SDK

var s3 = new AWS.S3({signatureVersion: 'v4'});

PHP SDK

									
$s3 = new S3Client(['signature' => 'v4']);

Python-Boto SDK

[s3] use-sigv4 = True

Ruby SDK

s3 = AWS::S3::Client.new(:s3_signature_version => :v4)
s3 = Aws::S3::Client.new(signature_version: 'v4')

.NET SDK

AWSConfigsS3.UseSignatureVersion4 = true;

つまり、AWS SDKを使っている場合は、バージョンを確認
– AWS SDK for Java v1 →Java 1.11.x あるいは v2 in Q4 2018 にアップグレード。
– AWS SDK for Java v2 ※アップグレード不要
– AWS SDK for .NET v1 →3.1.10 以降にアップグレード
– AWS SDK for .NET v2 →3.1.10 以降にアップグレード
– AWS SDK for .NET v3 ※アップグレード不要
– AWS SDK for JavaScript v1 →主要バージョン V3 in Q3 2019 にアップグレード
– AWS SDK for JavaScript v2 →2.68.0 以降にアップグレード
– AWS SDK for JavaScript v3 →主要バージョン V3 in Q3 2019 にアップグレード
– AWS SDK for PHP v1 →主要バージョン V3 にアップグレード
– AWS SDK for PHP v2 →主要バージョン V3 にアップグレード
– AWS SDK for PHP v3 ※アップグレード不要
– Boto2 →Boto2 v2.49.0 にアップグレード
– Boto3 →1.5.71 (Botocore)、1.4.6 (Boto3) にアップグレード
– AWS CLI →1.11.108 にアップグレード
– AWS CLI v2 ※アップグレード不要
– AWS SDK for Ruby v1 →Ruby V3 にアップグレード
– AWS SDK for Ruby v2 →Ruby V3 にアップグレード
– AWS SDK for Ruby v3 ※アップグレード不要
– Go ※アップグレード不要
– C++ ※アップグレード不要

pgrep httpd

pgrep
It is a command to search for process ID using a pattern that represents process name, user group, terminal name, etc. among running processes. You can use exetnded regular expression(10th) for patterns.

You can also use the pidof command to find the process ID from the command name.

[vagrant@localhost tests]$ pgrep httpd
1779
2082
2083
2084
2085
2086
2087
2088
2089

この数字はプロセスIDですな。