shell scriptで¥rの改行があると文字列結合がおかしくなる
https://stackoverflow.com/questions/12358814/concatenating-strings-in-bash-overwrites-them
#!/bin/sh str1="test1" str2="abcde" result=${str1}_${str2} echo $result result=$(echo ${str1} | tr -d '\r')_$(echo ${str2} | tr -d '\r') echo $result
$ sh test1.sh _abcde test1_abcde : command not found:
MacOSで接続していない外部ディスプレイの領域にウィンドウを移動させた時の対処方法
Chromeのウィンドウをドラッグさせたら画面から消えた。
画面下にある、Dockのアプリ一覧から、
Ctrl + マウスクリック でコンテキストメニューを表示して、
Options > Desktop on Display 1
メニューのZoomで直るという記事も何個かあったけど、直らなかった。
http://osxdaily.com/2013/08/14/move-window-back-on-screen-mac-os-x/
php 5.5が入っているCentOS6をyum update
エラー
$ sudo yum update --enablerepo=remi Loaded plugins: fastestmirror, presto Setting up Update Process Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * remi: mirror.innosol.asia * remi-safe: mirror.innosol.asia * updates: ftp.iij.ad.jp Resolving Dependencies --> Running transaction check ---> Package ConsoleKit.x86_64 0:0.4.1-3.el6 will be updated 省略 ---> Package yum-plugin-fastestmirror.noarch 0:1.1.30-37.el6 will be an update ---> Package zsh.x86_64 0:4.3.11-4.el6.centos.1 will be updated ---> Package zsh.x86_64 0:4.3.11-4.el6.centos.2 will be an update --> Finished Dependency Resolution Error: Package: gd-last-2.2.4-1.el6.remi.x86_64 (remi) Requires: libwebp.so.5()(64bit) Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi) Requires: php(api) = 20100412-x86-64 Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55) php(api) = 20121113-64 Available: php-common-5.3.3-46.el6_6.x86_64 (updates) php(api) = 20090626 Available: php-common-5.3.3-47.el6.x86_64 (base) php(api) = 20090626 Available: php-common-5.4.45-13.el6.remi.x86_64 (remi) php(api) = 20100412-x86-64 Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi) Requires: php(zend-abi) = 20100525-x86-64 Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55) php(zend-abi) = 20121212-64 Available: php-common-5.3.3-46.el6_6.x86_64 (updates) php(zend-abi) = 20090626 Available: php-common-5.3.3-47.el6.x86_64 (base) php(zend-abi) = 20090626 Available: php-common-5.4.45-13.el6.remi.x86_64 (remi) php(zend-abi) = 20100525-x86-64 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
$ sudo yum update --enablerepo=epel,rpmforge,remi Loaded plugins: fastestmirror, presto Setting up Update Process Loading mirror speeds from cached hostfile 省略 ---> Package yum-plugin-fastestmirror.noarch 0:1.1.30-37.el6 will be an update ---> Package zsh.x86_64 0:4.3.11-4.el6.centos.1 will be updated ---> Package zsh.x86_64 0:4.3.11-4.el6.centos.2 will be an update --> Running transaction check ---> Package libwebp.x86_64 0:0.4.3-3.el6 will be installed ---> Package perl-Time-HiRes.x86_64 4:1.9721-141.el6_7.1 will be installed ---> Package php-pecl-jsonc.x86_64 0:1.3.10-1.el6.remi.5.4 will be an update --> Processing Dependency: php(zend-abi) = 20100525-x86-64 for package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 --> Processing Dependency: php(api) = 20100412-x86-64 for package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 --> Finished Dependency Resolution Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi) Requires: php(api) = 20100412-x86-64 Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55) php(api) = 20121113-64 Available: php-common-5.3.3-46.el6_6.x86_64 (updates) php(api) = 20090626 Available: php-common-5.3.3-47.el6.x86_64 (base) php(api) = 20090626 Available: php-common-5.4.45-13.el6.remi.x86_64 (remi) php(api) = 20100412-x86-64 Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi) Requires: php(zend-abi) = 20100525-x86-64 Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55) php(zend-abi) = 20121212-64 Available: php-common-5.3.3-46.el6_6.x86_64 (updates) php(zend-abi) = 20090626 Available: php-common-5.3.3-47.el6.x86_64 (base) php(zend-abi) = 20090626 Available: php-common-5.4.45-13.el6.remi.x86_64 (remi) php(zend-abi) = 20100525-x86-64 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
remi-php55
sudo yum update --enablerepo=remi-php55,epel
で動いた。
Docker ubuntu Flaskアプリ用構築メモ
ubuntuでPython Flaskのアプリを途中まで作ったので、
Dockerfileでdockerコンテナを構築してみた。
pyenv install 2.7.13 が動かない
dockerのイメージを作るために、
ubuntuコンテナ内でコマンドラインで作業していたら、
pyenv でpython実行環境のインストールができなかった。
root@7101ef82c1b0:~# pyenv install 2.7.13 Downloading Python-2.7.13.tar.xz... -> https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
で止まる。エラーも出ない。
# apt-get install wget # wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
root@7101ef82c1b0:~# pyenv install 2.7.13 Downloading Python-2.7.13.tar.xz... -> https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz Installing Python-2.7.13... Installed Python-2.7.13 to /root/.pyenv/versions/2.7.13
環境変数
http://qiita.com/TakashiOshikawa/items/2b8974c242a7054e0be5
コピー
http://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory
http://qiita.com/ka2n/items/9659cb2b083ab7dcd844
Dockerfile でpip
一般ユーザーで
$ pip install appdirs
を実行したらエラー。
Installing collected packages: appdirs, beautifulsoup4, click, itsdangerous, Werkzeug, MarkupSafe, Jinja2, Flask, Flask-Script, SQLAlchemy, Flask-SQLAlchemy, lxml, pyparsing, six, packaging, requests Found existing installation: appdirs 1.4.3 Uninstalling appdirs-1.4.3: Exception: Traceback (most recent call last): File "/home/user1/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/home/user1/.local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run prefix=options.prefix_path, File "/home/user1/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 778, in install requirement.uninstall(auto_confirm=True) File "/home/user1/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 754, in uninstall paths_to_remove.remove(auto_confirm) File "/home/user1/.local/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove renames(path, new_path) File "/home/user1/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames shutil.move(old, new) File "/usr/lib/python2.7/shutil.py", line 303, in move os.unlink(src) OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/appdirs-1.4.3.dist-info/DESCRIPTION.rst'
pythonの場所がpyenvのものじゃないのでおかしい。
RUN set -x eval "$(pyenv init -)" RUN which pip
の結果が
Step 14/19 : RUN which pip ---> Running in fa1d2bb21a7d /usr/bin/pip
なので、おかしい。
途中までできたdocker containerのターミナルでwhichすると.pyenvのパスになる。
$ eval "$(pyenv init -)" $ which pip /home/user1/.pyenv/shims/pip
apt-getでpipを入れたのがいけなかったっぽい。
RUN apt-get -y install \ sudo \ python-pip
Dockerfile でpip その2
まだエラーが直らない。
Removing intermediate container 96a19160fbe0 Step 19/19 : RUN pyenv global llnw && cd /var/www/llnw && pip install -r requirements.txt ---> Running in cc1395735ef6 Collecting beautifulsoup4==4.5.3 (from -r requirements.txt (line 2)) 省略 Installing collected packages: beautifulsoup4, click, itsdangerous, Werkzeug, MarkupSafe, Jinja2, Flask, Flask-Script, SQLAlchemy, Flask-SQLAlchemy, lxml, pyparsing, requests Exception: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run prefix=options.prefix_path, File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 784, in install **kwargs File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 851, in install self.move_wheel_files(self.source_dir, root=root, prefix=prefix) File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files isolated=self.isolated, File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 345, in move_wheel_files clobber(source, lib_dir, True) File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 316, in clobber ensure_dir(destdir) File "/usr/local/lib/python2.7/dist-packages/pip/utils/__init__.py", line 83, in ensure_dir os.makedirs(path) File "/usr/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/bs4'
RUN eval "$(pyenv init -)" && \ pyenv global env1 && \ cd /var/www/app1 && \ pip install -r requirements.txt
のようにしたら動いた。
COPY コマンド
DockerfileのCOPYは、コマンドを実行したディレクトリ以下のファイルしかコピーできないらしい。
Step 5/5 : COPY ../ /var/www/appname1/ Forbidden path outside the build context: ../ ()
http://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory
flaskアプリのルートにdocker.sh
プロジェクトのルートディレクトリにdocker.shファイルを作って、
そこから docker build をした。
sudo
ubuntuには、sudoというグループがある。
/etc/sudoers
に許可設定が書かれていて、このグループに入れるとsudoできるようになる。
# Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL
起動用スクリプト
docker.sh
#!/bin/bash APP_IMAGE_NAME=app1_image # build image docker build -t=$APP_IMAGE_NAME -f ./deploy/docker/Dockerfile .
Dockerfile
# call this file from ../docker.sh FROM ubuntu RUN apt-get -y update RUN apt-get -y install \ build-essential \ git \ gcc \ make \ openssl \ libssl-dev \ libbz2-dev \ libreadline-dev \ libsqlite3-dev \ wget \ vim \ python RUN apt-get -y install \ sudo \ curl RUN curl -kL https://bootstrap.pypa.io/get-pip.py | python # TODO set password properly RUN useradd -m -s /bin/bash user1 && \ echo 'user1:user1' | chpasswd RUN usermod -aG sudo user1 USER user1 ENV HOME /home/user1 RUN git clone https://github.com/yyuu/pyenv.git ~/.pyenv RUN git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv ENV PYENV_ROOT $HOME/.pyenv ENV PATH $PYENV_ROOT/bin:$PATH USER root RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' | tee -a /etc/profile.d/pyenv.sh RUN echo 'export PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"' | tee -a /etc/profile.d/pyenv.sh USER user1 RUN pyenv install 2.7.13 RUN pyenv virtualenv 2.7.13 app1 COPY . /var/www/app1/ RUN eval "$(pyenv init -)" && \ pyenv global app1 && \ cd /var/www/app1 && \ pip install -r requirements.txt USER root RUN chown -R user1:user1 /var/www/app1/ USER user1 RUN echo '' >> ~/.bashrc && \ echo 'eval "$(pyenv init -)"' >> ~/.bashrc RUN eval "$(pyenv init -)" && \ cd /var/www/app1 && \ python manage.py init_db
メモ
http://kubotti.hatenablog.com/entry/2017/02/08/110755
https://mzmttks.blogspot.jp/2011/12/python-site-packagesdist-packages.html
http://qiita.com/erscl/items/8d17b9d2d7a6a2ca0a57
http://cheng.logdown.com/posts/2015/06/14/-usr-bin-pip-no-such-file-or-directory
シンギュラリティまであと何日
シンギュラリティが起こるとされる、2045年まであと28年。
28 * 365 = 10220
なので、あと1万日くらい。
キリのいい数字だったので、今日から何日後なのか調べてみた。
あと、ちょうど10000日の日付も調べてみた。
from time import time, mktime from datetime import datetime, timedelta # calculate remaining days to the year 2045 ts = time() print datetime.fromtimestamp(ts).strftime('%Y/%m/%d %H:%M:%S') ts_xday = mktime(datetime.strptime('2045/1/1', '%Y/%m/%d').timetuple()) delta1 = timedelta(seconds=(ts_xday - ts)) print delta1 # when is the date which 10000 days remain. ts10000 = ts_xday - timedelta(days=10000).total_seconds() print datetime.fromtimestamp(ts10000).strftime('%Y/%m/%d')
2017/03/26 23:22:52 10142 days, 0:37:07.029797 2017/08/16
結果は、2017/03/26 からだと、あと10142日だった。
ちょうど10000万日になるのは2017/08/16
2038年問題?
codepadというサイトで実行したら、エラーになった。
メモ
Wikipediaを見たらシンギュラリティの予測は、2029年になったと書いてあった。
技術的特異点 - Wikipedia
レイ・カーツワイルは、技術的特異点論者として2017年3月10日から2017年3月19日にかけて米国テキサス州で開催されたSXSW Conferenceに登壇した。その議論の中で、技術開発の進捗が2005年当時の予測より早くなっているとして、技術的特異点の到来が2029年に早まるとの見方を示した。[3]
sudo関連のメモ
visudo
visudo コマンドで編集するファイルは、
/etc/sudoers
ubuntuでsudoできるようにする設定
dockerコンテナで作業。
Ubuntu 16.04.2 LTS
実行するコマンド
useradd -m user1 echo 'user1:pass1' | chpasswd usermod -aG sudo user1
Dockerfileに書く場合
RUN useradd -m user1 && \ echo 'user1:pass1' | chpasswd RUN usermod -aG sudo user1
sudoというグループに追加するだけでsudoできるようになるのは、
/etc/sudoers
# Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL
と書かれているから(だと思う)。
CentOS 6 だと書かれてなかった。
https://sites.google.com/site/teyasn001/home/sudo
amazon linux ec2-user no password
AWSのAmazonLinux 、ubuntu で初期ユーザーのsudoでパスワードが不要なのは、
/etc/sudoers.d/cloud-init
に
user ALL = NOPASSWD: ALL
と書かれているからだった。
/etc/sudoers の最後に /etc/sudoers.d の中のファイルを include してるっぽい記述がある。
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment) #includedir /etc/sudoers.d
初期アカウントがパスワード無しでsudo出来るのが気持ち悪いという貴方へ – サーバーワークスエンジニアブログ
Amazon EC2にSudoユーザーを追加する。 - Qiita
/etc/sudoers /etc/sudoers.d/cloud-init
cloud-init
sudoとはあまり関係なさそうだけど cloud-init の記事。
http://dev.classmethod.jp/cloud/aws/cloud-init-cfg/
MacのTerminalでマウスのスクロールが履歴表示になる
OS X Yosemite
Version 10.10.5
Terminalを使っているとマウスのスクロールが、
画面のスクロールではなくて、コマンドの入力履歴になることがある。
Shiftキーを押しながらスクロールで、画面スクロールと入力履歴のスクロールを切り替えられた。
メニューバーの
Terminal -> Preferences -> Profiles -> Keyboard -> Scroll Alternate screen
でも切り替えられる。
メモ
この件を調べていたら見つけたGoogleMapの小技
https://iritec.jp/selfhack/9775/