haiju's 開発メモ

開発に必要な情報を自分用にメモ

cronで土日判定を仕込んだAutoMysqlBackup.shがWindows改行コードでエラーになったのでLinux向けに変換

ちなみに、自分は依頼されたスクリプトをCentOS7の環境で

修正したものをcronで時間指定をして実施した。

成功したらメールが飛んでくるはずだけど、メールが飛んで

来なくて、ログファイル(/var/log/maillog)を確認するとエラー

でコケてた。

で、/var/spool/mail/root に新しいメールが来てるって通知を

見たら、以下のエラーが(ΦωΦ)

/root/automysqlbackup.sh: 行 97: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 100: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 103: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 106: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 109: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 351: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 366: $'\r': コマンドが見つかりません
/root/automysqlbackup.sh: 行 423: 予期しないトークン `$'{\r'' 周辺に構文エラーがあります
'root/automysqlbackup.sh: 行 423: `dbdump () {

 Linuxの改行コードは'\n'だから、Windowsの改行コードの'\r\n'の'\r'を

コマンドと認識してしまったらしいね。

そこで、Windowsの改行コードをLinux向けに変換する必要がある。

Windows改行コードをUNIX改行コード変換」でググると、だいたい

trコマンドかnkfコマンドで変換する方法が上の方に上がってくる

けど、なかなかうまくいかないし、実行環境にnkfコマンドが

インストールされていなかったので、dos2unix をインストール

して使ってみる。

[手順]

1. dos2unixをCentOS7環境にyumでインストール。

# yum install -y dos2unix

2. fileコマンドで変換前のファイルの改行コードを確認。

# file automysqlbackup.sh.org

automysqlbackup.sh.org: Bourne-Again shell script, Non-ISO extended-ASCII text executable, with CRLF line terminators

3. dos2unixコマンドを使い、Windows用の改行コードを

 UNIX用に変換。

# dos2unix automysqlbackup.sh.org

4. 改めてfileコマンドで変換後のファイルの改行コードを確認。

# file automysqlbackup.sh.org
automysqlbackup.sh.org: Bourne-Again shell script, Non-ISO extended-ASCII text executable

※末尾に「, with CRLF line terminators」がなければOK。

[参考サイト]

qiita.com

qiita.com

www.unix-power.net

bashスクリプトで曜日判定

いまだこのかた、シェルスクリプトを書いたことがなかったので

備忘録として(ΦωΦ;)

(ex)土日を判定する

#!/bin/bash

DAYOFWEEK=`date +%u`

if [ $DAYOFWEEK -eq 6 -o $DAYOFWEEK -eq 7 ]; then

または

if [ $DAYOFWEEK -eq 6 ] || [$DAYOFWEEK -eq 7 ]; then

[参考サイト]

date コマンド | コマンドの使い方(Linux) | hydroculのメモ

shiraji.hatenablog.com

www.harumaki.net

qiita.com

shuzo-kino.hateblo.jp

magazine.re-web.org

shellscript.sunone.me

シェルのif文でAND条件を複数指定したい | OpenGroove

qiita.com

eng-entrance.com

逆引きシェルスクリプト/if文の条件式でand, or, notを使う方法 - Linuxと過ごす

Manjaro Fluxbox 15.12_x86-64にインストールしたNode.js v8.9.4でPurescriptをインストール

jQueryは嫌いだけどJSでUIはもはや避けて通れないから何か

JSの処理系を覚えるとしたら何にしようか?ってことで、

Haskellをやってる人がまともな言語はPurescriptって言っていた

のを思い出して、ElmもいいけどあれはWebUIに特化してる気が

したので、この際、Purescriptにどっぷり沈んでみようと思って

環境を再構築した備忘録をまとめてみる(ΦωΦ)

さっきの記事の続きだけどwww

[手順]

1.npmでシステム全体にpurescriptをインストール。

% npm install -g purescript

/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/purs -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin

> purescript@0.11.7 postinstall /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript
> install-purescript --purs-ver=0.11.7 --name=purs.bin .
 
✔ Check if a prebuilt 0.11.7 binary is provided for Linux (12s)
✔ Download the prebuilt PureScript binary (3s)
✖ Verify the prebuilt binary works correctly
Error: Command failed: /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin --version

 /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No suc h file or directory
at Promise.all.then.arr (/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/node_modules/execa/index.js:231:11)
at <anonymous>
▬ Save the downloaded binary to the cache directory
 
↓ Fallback: building from source
 
✔ Check if 'stack' command is available
✔ Check if 'stack' command is available
1.6.3.1 found at /usr/bin/stack
✔ Download the PureScript 0.11.7 source (7s)
✔ Ensure the appropriate GHC is installed (1m)
✔ Build a binary from source (19m)
✔ Save the built binary to the cache directory (3s)
 
Installed to ~/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/purescript/purs.bin
Cached to ~/.cache/purescript/npm/v0.11.7-linux-x64.tgz
 
+ purescript@0.11.7
added 118 packages in 1279.453s

2.purescriptのビルドツールのpulp,パッケージマネージャ?のbowerをインストール。

% npm install -g pulp bower

3.実行中にnpmをアップデートしろというメッセージが出るのでアップデート。

% npm i -g npm

/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/npm -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/npm/bin/npm-cli.js
/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/npx -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/npm/bin/npx-cli.js
+ npm@5.7.1
added 63 packages, removed 6 packages and updated 49 packages in 14.294s

4.改めて、pulpとbowerをインストール。

% npm install -g pulp bower

npm WARN deprecated bower@1.8.2: ...psst! Your project can stop working at any moment because its dependencies can change. Prevent this by migrating to Yarn: https://bower.io/blog/ 2017/how-to-migrate-away-from-bower/
/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/bower -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/bower/bin/bower
/home/haiju/.anyenv/envs/nodenv/versions/8.9.4/bin/pulp -> /home/haiju/.anyenv/envs/nodenv/versions/8.9.4/lib/node_modules/pulp/index.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/pulp/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
 
+ pulp@12.0.1
+ bower@1.8.2
updated 2 packages in 19.467s

5.pulpとbowerのPATHを.zshrcに設定し、再起動。

vim ~/.zchrc

export PATH="$HOME/.anyenv/envs/nodenv/versions/8.9.4/bin/bower:$PATH"

export PATH="$HOME/.anyenv/envs/nodenv/versions/8.9.4/bin/pulp:$PATH"

% source ~/.zshrc

6.pulpとbowerの動作確認のため、サンプルプログラム (Hello, world)を作成。

6-1.まず pulp init で任意のプロジェクト「hello-pur」プロジェクト作成。

pulp init
* Generating project skeleton in /home/haiju/workspace/hello-pur
bower purescript-console#* cached https://github.com/purescript/purescript-console.git#2.0.0
bower purescript-console#* validate 2.0.0 against https://github.com/purescript/purescript-console.git#*
bower purescript-prelude#* cached https://github.com/purescript/purescript-prelude.git#3.1.1
bower purescript-prelude#* validate 3.1.1 against https://github.com/purescript/purescript-prelude.git#*
bower purescript-console#* new version for https://github.com/purescript/purescript-console.git#*
bower purescript-console#* resolve https://github.com/purescript/purescript-console.git#*
bower purescript-console#* download https://github.com/purescript/purescript-console/archive/v3.0.0.tar.gz
bower purescript-console#* extract archive.tar.gz
bower purescript-console#* resolved https://github.com/purescript/purescript-console.git#3.0.0
bower purescript-eff#^3.0.0 cached https://github.com/purescript/purescript-eff.git#3.1.0
bower purescript-eff#^3.0.0 validate 3.1.0 against https://github.com/purescript/purescript-eff.git#^3.0.0
bower purescript-eff#^3.0.0 new version for https://github.com/purescript/purescript-eff.git#^3.0.0
bower purescript-eff#^3.0.0 resolve https://github.com/purescript/purescript-eff.git#^3.0.0
bower purescript-eff#^3.0.0 download https://github.com/purescript/purescript-eff/archive/v3.2.0.tar.gz
bower purescript-eff#^3.0.0 extract archive.tar.gz
bower purescript-eff#^3.0.0 resolved https://github.com/purescript/purescript-eff.git#3.2.0
bower purescript-monoid#^3.3.0 cached https://github.com/purescript/purescript-monoid.git#3.3.0
bower purescript-monoid#^3.3.0 validate 3.3.0 against https://github.com/purescript/purescript-monoid.git#^3.3.0
bower purescript-newtype#^2.0.0 cached https://github.com/garyb/purescript-newtype.git#2.0.0
bower purescript-newtype#^2.0.0 validate 2.0.0 against https://github.com/garyb/purescript-newtype.git#^2.0.0
bower purescript-invariant#^3.0.0 cached https://github.com/purescript/purescript-invariant.git#3.0.0
bower purescript-invariant#^3.0.0 validate 3.0.0 against https://github.com/purescript/purescript-invariant.git#^3.0.0
bower purescript-control#^3.0.0 cached https://github.com/purescript/purescript-control.git#3.3.1
bower purescript-control#^3.0.0 validate 3.3.1 against https://github.com/purescript/purescript-control.git#^3.0.0
bower purescript-prelude#^3.0.0 install purescript-prelude#3.1.1
bower purescript-console#^3.0.0 install purescript-console#3.0.0
bower purescript-eff#^3.0.0 install purescript-eff#3.2.0
bower purescript-monoid#^3.3.0 install purescript-monoid#3.3.0
bower purescript-invariant#^3.0.0 install purescript-invariant#3.0.0
bower purescript-newtype#^2.0.0 install purescript-newtype#2.0.0
bower purescript-control#^3.0.0 install purescript-control#3.3.1

purescript-prelude#3.1.1 bower_components/purescript-prelude

purescript-console#3.0.0 bower_components/purescript-console
└── purescript-eff#3.2.0
 
purescript-eff#3.2.0 bower_components/purescript-eff
├── purescript-monoid#3.3.0
└── purescript-prelude#3.1.1
 
purescript-monoid#3.3.0 bower_components/purescript-monoid
├── purescript-control#3.3.1
├── purescript-invariant#3.0.0
└── purescript-newtype#2.0.0
 
purescript-invariant#3.0.0 bower_components/purescript-invariant
└── purescript-prelude#3.1.1
 
purescript-newtype#2.0.0 bower_components/purescript-newtype
└── purescript-prelude#3.1.1
 
purescript-control#3.3.1 bower_components/purescript-control
└── purescript-prelude#3.1.1

bower purescript-psci-support#* cached https://github.com/purescript/purescript-psci-support.git#2.0.0
bower purescript-psci-support#* validate 2.0.0 against https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#* new version for https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#* resolve https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#* download https://github.com/purescript/purescript-psci-support/archive/v3.0.0.tar.gz
bower purescript-psci-support#* extract archive.tar.gz
bower purescript-psci-support#* resolved https://github.com/purescript/purescript-psci-support.git#3.0.0
bower purescript-psci-support#^3.0.0 install purescript-psci-support#3.0.0
 
purescript-psci-support#3.0.0 bower_components/purescript-psci-support
└── purescript-console#3.0.0

7.途中でbowerもアップデートできるよメッセージが出るが今回は無視。

 ※アップデートする場合は以下。

% npm i -g bower to update

8.pulp buildコマンドでビルド。

 6で作成したhello-pursプロジェクトをビルド。

pulp build

* Building project in /home/haiju/workspace/hello-pur
Compiling Data.Boolean
Compiling Data.NaturalTransformation
Compiling Data.Show
Compiling Control.Semigroupoid
Compiling Control.Category
Compiling Data.Function
Compiling Data.Unit
Compiling Data.Void
Compiling Control.Lazy
Compiling Data.Semiring
Compiling Data.Semigroup
Compiling Data.HeytingAlgebra
Compiling Data.Eq
Compiling Data.Functor
Compiling Data.Ring
Compiling Control.Apply
Compiling Control.Alt
Compiling Data.CommutativeRing
Compiling Control.Plus
Compiling Control.Extend
Compiling Data.BooleanAlgebra
Compiling Data.Functor.Invariant
Compiling Data.Ordering
Compiling Data.EuclideanRing
Compiling Control.Comonad
Compiling Control.Applicative
Compiling Data.Ord.Unsafe
Compiling Data.Ord
Compiling Control.Bind
Compiling Control.Alternative
Compiling Data.DivisionRing
Compiling Data.Field
Compiling Control.Monad
Compiling Control.MonadZero
Compiling Data.Bounded
Compiling Control.MonadPlus
Compiling Prelude
Compiling Data.Monoid
Compiling Data.Newtype
Compiling Control.Monad.Eff
Compiling Data.Monoid.Multiplicative
Compiling Data.Monoid.Dual
Compiling Data.Monoid.Endo
Compiling Control.Monad.Eff.Console
Compiling Data.Monoid.Conj
Compiling Data.Monoid.Alternate

Compiling Control.Monad.Eff.Uncurried
Compiling Data.Monoid.Disj
Compiling Control.Monad.Eff.Class
Compiling Data.Monoid.Additive
Compiling Control.Monad.Eff.Unsafe
Compiling Main
Compiling PSCI.Support
* Build successful.

9.pulp test コマンドでテスト実行。

pulp test
* Building project in /home/haiju/workspace/hello-pur
Compiling Test.Main
* Build successful.
* Running tests...
You should add some tests.
* Tests OK.

10.purescriptのREPLのpsciを起動してみる。

pulp repl
Compiling Data.NaturalTransformation
Compiling Data.Boolean
Compiling Control.Semigroupoid
Compiling Data.Show
Compiling Control.Category
Compiling Data.Void
Compiling Data.Unit
Compiling Data.Function
Compiling Data.HeytingAlgebra
Compiling Control.Lazy
Compiling Data.Semigroup
Compiling Data.Eq
Compiling Data.Semiring
Compiling Data.Functor
Compiling Data.BooleanAlgebra
Compiling Data.Ordering
Compiling Data.Ring
Compiling Control.Alt
Compiling Data.Functor.Invariant
Compiling Control.Extend
Compiling Control.Apply
Compiling Control.Plus
Compiling Data.CommutativeRing
Compiling Data.Ord.Unsafe
Compiling Data.Ord
Compiling Control.Comonad
Compiling Data.EuclideanRing
Compiling Control.Applicative
Compiling Data.DivisionRing
Compiling Data.Field
Compiling Control.Alternative
Compiling Control.Bind
Compiling Data.Bounded
Compiling Control.Monad
Compiling Control.MonadZero
Compiling Prelude
Compiling Control.MonadPlus
Compiling Data.Newtype
Compiling Data.Monoid
Compiling Control.Monad.Eff
Compiling Data.Monoid.Additive
Compiling Data.Monoid.Dual
Compiling Control.Monad.Eff.Class
Compiling Data.Monoid.Alternate

Compiling Data.Monoid.Endo
Compiling Control.Monad.Eff.Unsafe
Compiling Data.Monoid.Disj
Compiling Data.Monoid.Multiplicative
Compiling Data.Monoid.Conj
Compiling Control.Monad.Eff.Uncurried
Compiling Control.Monad.Eff.Console
Compiling Test.Main
Compiling Main
Compiling PSCI.Support
PSCi, version 0.11.7
Type :? for help
 
import Prelude
>
>
See ya!

 ※ターミナルに戻るには「Ctrl + d」

11.サンプルプロジェクトの中身を見てみる。

 % vim ~/workspace/hello-pur/src/Main.purs

module Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
 
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
log "Hello sailor!"  ---  ここを"Hello, world!"と変更する

12.pulp runコマンドでサンプルプロジェクトの実行。

pulp run
* Building project in /home/haiju/workspace/hello-pur
* Build successful.
Hello, world!

 ※実行はせずにビルドのみ済ませたい場合は、pulp buildコマンド。

13.テスト実行。

  ※pulp testコマンドを実行すると、src/Main.pursのMainモジュール

  ではなく、test/Main.pursのTest.Mainモジュールが実行される。

% pulp test
* Building project in /home/haiju/workspace/hello-pur
* Build successful.
* Running tests...
You should add some tests.
* Tests OK.

[参考サイト]

qiita.com

documentation/Getting-Started.md at master · purescript/documentation · GitHub

purescript/INSTALL.md at master · purescript/purescript · GitHub

 

 

Manjaro Fluxbox 15.12_x86-64のanyenvにnodenvをインストールしてNode.js v8.9.4インストール

ようやく仕事が落ち着いてきたので、インストール済みのanyenvに

nodenvを導入してNode.js v8.9.4をインストールした作業の備忘録

をまとめてみる。

anyenvは既にCrystalインストールで導入済みだった。

pacmanでもインストールできるけど後々、動かしたいAltJSによって

バージョンが違ったりして面倒くさくなるので、初めからanyenvで

管理しとけよって、お話だが(ΦωΦ)

[手順]

1.anyenvでインストール可能な**envを検索。

% anyenv install --list
Available **envs:
Renv
crenv
denv
erlenv
exenv
goenv
hsenv
jenv
luaenv
ndenv
nenv
nodenv
phpenv
plenv
pyenv
rbenv
sbtenv
scalaenv
swiftenv

2.nodenvをインストール。

% anyenv install nodenv

3.シェルを再起動。

% exec $SHELL -l

4.nodenvコマンドを叩き使い方を確認。

% nodenv
nodenv 1.1.2-1-g18489d7
Usage: nodenv <command> [<args>]
 
Some useful nodenv commands are:
commands List all available nodenv commands
local Set or show the local application-specific Node version
global Set or show the global Node version
shell Set or show the shell-specific Node version
install Install a Node version using node-build
uninstall Uninstall a specific Node version
rehash Rehash nodenv shims (run this after installing executables)
version Show the current Node version and its origin
versions List all Node versions available to nodenv
which Display the full path to an executable
whence List all Node versions that contain the given executable
 
See `nodenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/nodenv/nodenv#readme

5.参考にしているサイトによれば、2017/11時点で安定版の最新はv8.9だが

 インストール可能バージョンの確認すると安定版の最新はv8.10なので

 1つ前のv8.9.4をインストール。

※インストール可能バージョンの確認

% nodenv install --list

※インストール実行

% nodenv install 8.9.4
Downloading node-v8.9.4-linux-x64.tar.gz...
-> https://nodejs.org/dist/v8.9.4/node-v8.9.4-linux-x64.tar.gz
Installing node-v8.9.4-linux-x64...
Installed node-v8.9.4-linux-x64 to /home/haiju/.anyenv/envs/nodenv/versions/8.9.4

6.versionを確認。

% nodenv versions

8.9.4

7,とりあえずシステム全体に適用。

% nodenv global 8.9.4

8.シェルを再起動。

% exec $SHELL -l

9.バージョンを確認。

 v8.9.4が表示されればOK。

% node -v

v8.9.4

[参考サイト]

anyenvとnodenvでNode.jsのバージョン管理をしよう! - to-R Media

 

Manjaro Fluxbox 15.12_x86-64でNodejs-lts-boronとそれに依存したパッケージを削除する

lts版のNode.jsをpacmanでインストールしてたけど、他の

バージョンを試してもみたいし、purescriptのバイナリを

試したいし、anyenv + nodenvで複数管理もしたいよね。

ってことで、lts-boronを以前、手動で削除したのだが

キャッシュを参照されてまたインストールされてしまった

ので、ここはpacmanで依存してるパッケージごと削除して

しまえ!!!ってことでメモ(ΦωΦ)

[手順]

1. 以下のオプションを付けてpacmanを実行。

% sudo pacman -Rsc nodejs-lts-boron
依存関係を確認しています...

パッケージ (4) c-ares-1.13.0-1 http-parser-2.8.0-1 semver-5.5.0-1 nodejs-lts-boron-6.12.3-1

合計削除容量: 16.53 MiB

:: 以上のパッケージを削除しますか? [Y/n] y
:: パッケージの変更を処理しています...
(1/4) 削除 semver [########################################################] 100%
(2/4) 削除 nodejs-lts-boron [########################################################] 100%
(3/4) 削除 http-parser [########################################################] 100%
(4/4) 削除 c-ares [########################################################] 100%
:: トランザクション後のフックを実行...
(1/1) Arming ConditionNeedsUpdate...

※-Rscで削除したいパッケージとそのパッケージが必要としている

 他のパッケージ、さらに削除したいパッケージに依存している

 パッケージを再帰的に削除。

[参考サイト]

pacman - ArchWiki

malkalech.com

qiita.com

au Walletで取得したポイントをプリペイドカードにチャージする

au Wallet (プリペイドカード)の残金が残り少なくなった

場合、オートチャージを設定していると、「かんたん

決済」で毎月の使用料と共にチャージされるけど、

それは混乱の元なのでWalletのポイントでチャージする

にはどうしたらいいんだろう?ということで、実際に

試してみた手順を備忘録としてメモ(ΦωΦ)

[手順]

1.お使いのスマホau Walletアプリを起動。

2.TOP画面の「入金(チャージ)」ボタンをクリック。

3.チャージ画面が表示されるので、下の「その他

 チャージ方法」にある「ポイント」をクリック。

4.ポイントを100円単位でチャージできる画面になる

 ので、1081ポイントのうち1000円を指定して実行。

※textの右に「00」がついているので、100円単位の

 場合は1~9の数字を指定し、1000円以上の場合は

 10以上の数字を指定。

プリペイドカードの場合は、合計20000円までしか

 チャージできないので、最大200まで指定可能。

5.チャージボタンを実行しても、確認画面が出てそこで

 「チャージ」ボタンを実行しないと反映されないので

 注意が必要。

 「戻る」ボタンはチャージキャンセルという意味に注意。

※自分は、確認画面に来た時にチャージ完了だと勘違いして

 しまったため、2回ほどチャージし直したw

[参考サイト]

プリペイドカードへのチャージ(入金)方法 | ご利用ガイド | au WALLET

CakePHP3.xを起動時、DBエラーでTOPページを表示できない場合

いろいろ調べたけど、~/app_name/tmp ディレクト

自体の権限が「777」に設定されていないことが多い。

[手順]

1. ~/app_name/tmp ディレクトリのアクセス権限を「777」に設定。

# cd tmp

# chmod -R 777 ./tmp

2. ブラウザからTOPページのURLを実行し、表示されればOK。

[参考サイト]

takuya-1st.hatenablog.jp

qiita.com

stackoverflow.com

www.dragonbe.com

fredericiana.com