読者です 読者をやめる 読者になる 読者になる

メモ。

ただのメモです。

find コマンドが何気に便利だった。

Linux shell

ソースファイルの文字コードが、Shift_JISだった所為で文字化けコメントばっかじゃん。一括変換してやった。

# find . -name "*.java" -exec nkf -w --overwrite {} \;

それと、何気にって表現が若者言葉だったことを、初めて知った。


参考

FIngerprint 確認がウザイので無効にしてしまえ。

ansible Linux

1 Ansibleの設定ファイルに記述する場合

$ cat ansible.cfg

[defaults]

host_key_checking = False

2 環境変数で設定する場合

$ export ANSIBLE_HOST_KEY_CHECKING=False

3 opensshの設定を変更する場合

$ cat ~/.ssh/config

StrictHostKeyChecking no

4 コマンド実行時に無効とする場合

$ ssh -o StrictHostKeyChecking=no IPアドレス

バックスラッシュの入力

MacBook Air(日本語キーボード)で「\」を入力したいなら、option + ¥


参考

pythonのcalendar モジュール

カレンダーモジュール

In [1]: import calendar

In [2]: list(calendar.day_name)
Out[2]: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

In [3]: calendar.weekday(2016, 12, 22)
Out[3]: 3

In [4]: list(calendar.day_name)[3]
Out[4]: 'Thursday'

In [5]: print(calendar.TextCalendar(firstweekday=6).formatyear(2016))

Pythonのset オブジェクト

python
  • 集合型

  • set オブジェクトは、固有の hashable オブジェクトの順序なしコレクション

下記の様な結果が面白かったので、記録。

In [1]: {"B", "C"} - {"A"}
Out[1]: {'B', 'C'}

In [2]: {"A", "C"} - {"A"}
Out[2]: {'C'}

CentOS7.x LiveCDで遊ぶ (2)

Linux centos bash

CentOS7.x LiveCDで遊ぶ(1) - メモ。の続き。 squashes.imgを解凍して得られるex3fs.imgを適当なディレクトリへマウントすると、以下の様なディレクトリを確認出来る。

 $ mount -o loop,rw  squashfs-root/LiveOS/ext3fs.img /mnt
 $ cd /mnt
 $ ls /mnt
 bin   dev  home  lib64       media  opt   root  sbin  sys  usr
 boot  etc  lib   lost+found  mnt    proc  run   srv   tmp  var
  1. initスクリプト(/mnt/etc/init.d/livesys)の96, 97行目で利用している関数findPersistentHomeを追っていくと、persistenthome=UUID=XXXXXXXXXXや persistenthome=LABEL=/homeで指定した区画をホームディレクトリとしてマウント出来ることがわかる。

  2. 指定した区画をホームディレクトリとしてマウントするには、grub.cfgもしくは、syslinux.cfg(両方でも良い)のkernel lineへpersistenthome=......を追記する。

    例 kernel ........... persistenthome=LABEL=/HOME

$ nl -b a  /mnt/etc/init.d/livesys
     1  #
     2  # live: Init script for live image
     3  #
     4  # chkconfig: 345 00 99
     5  # description: Init script for live image.
     6  ### BEGIN INIT INFO
     7  # X-Start-Before: display-manager
     8  ### END INIT INFO
     9  
    10  . /etc/init.d/functions
    11  
    12  if ! strstr "`cat /proc/cmdline`" rd.live.image || [ "$1" != "start" ]; then
    13      exit 0
    14  fi
    15  
    16  if [ -e /.liveimg-configured ] ; then
    17      configdone=1
    18  fi
    19  
    20  exists() {
    21      which $1 >/dev/null 2>&1 || return
    22      $*
    23  }
    24  
    25  # Make sure we don't mangle the hardware clock on shutdown
    26  ln -sf /dev/null /etc/systemd/system/hwclock-save.service
    27  
    28  livedir="LiveOS"
    29  for arg in `cat /proc/cmdline` ; do
    30    if [ "${arg##rd.live.dir=}" != "${arg}" ]; then
    31      livedir=${arg##rd.live.dir=}
    32      return
    33    fi
    34    if [ "${arg##live_dir=}" != "${arg}" ]; then
    35      livedir=${arg##live_dir=}
    36      return
    37    fi
    38  done
    39  
    40  # enable swaps unless requested otherwise
    41  swaps=`blkid -t TYPE=swap -o device`
    42  if ! strstr "`cat /proc/cmdline`" noswap && [ -n "$swaps" ] ; then
    43    for s in $swaps ; do
    44      action "Enabling swap partition $s" swapon $s
    45    done
    46  fi
    47  if ! strstr "`cat /proc/cmdline`" noswap && [ -f /run/initramfs/live/${livedir}/swap.img ] ; then
    48    action "Enabling swap file" swapon /run/initramfs/live/${livedir}/swap.img
    49  fi
    50  
    51  mountPersistentHome() {
    52    # support label/uuid
    53    if [ "${homedev##LABEL=}" != "${homedev}" -o "${homedev##UUID=}" != "${homedev}" ]; then
    54      homedev=`/sbin/blkid -o device -t "$homedev"`
    55    fi
    56  
    57    # if we're given a file rather than a blockdev, loopback it
    58    if [ "${homedev##mtd}" != "${homedev}" ]; then
    59      # mtd devs don't have a block device but get magic-mounted with -t jffs2
    60      mountopts="-t jffs2"
    61    elif [ ! -b "$homedev" ]; then
    62      loopdev=`losetup -f`
    63      if [ "${homedev##/run/initramfs/live}" != "${homedev}" ]; then
    64        action "Remounting live store r/w" mount -o remount,rw /run/initramfs/live
    65      fi
    66      losetup $loopdev $homedev
    67      homedev=$loopdev
    68    fi
    69  
    70    # if it's encrypted, we need to unlock it
    71    if [ "$(/sbin/blkid -s TYPE -o value $homedev 2>/dev/null)" = "crypto_LUKS" ]; then
    72      echo
    73      echo "Setting up encrypted /home device"
    74      plymouth ask-for-password --command="cryptsetup luksOpen $homedev EncHome"
    75      homedev=/dev/mapper/EncHome
    76    fi
    77  
    78    # and finally do the mount
    79    mount $mountopts $homedev /home
    80    # if we have /home under what's passed for persistent home, then
    81    # we should make that the real /home.  useful for mtd device on olpc
    82    if [ -d /home/home ]; then mount --bind /home/home /home ; fi
    83    [ -x /sbin/restorecon ] && /sbin/restorecon /home
    84    if [ -d /home/liveuser ]; then USERADDARGS="-M" ; fi
    85  }
    86  
    87  findPersistentHome() {
    88    for arg in `cat /proc/cmdline` ; do
    89      if [ "${arg##persistenthome=}" != "${arg}" ]; then
    90        homedev=${arg##persistenthome=}
    91        return
    92      fi
    93    done
    94  }
    95  
    96  if strstr "`cat /proc/cmdline`" persistenthome= ; then
    97    findPersistentHome
    98  elif [ -e /run/initramfs/live/${livedir}/home.img ]; then
    99    homedev=/run/initramfs/live/${livedir}/home.img
   100  fi
   101  
   102  # if we have a persistent /home, then we want to go ahead and mount it
   103  if ! strstr "`cat /proc/cmdline`" nopersistenthome && [ -n "$homedev" ] ; then
   104    action "Mounting persistent /home" mountPersistentHome
   105  fi
   106  
   107  # make it so that we don't do writing to the overlay for things which
   108  # are just tmpdirs/caches
   109  mount -t tmpfs -o mode=0755 varcacheyum /var/cache/yum
   110  mount -t tmpfs vartmp /var/tmp
   111  [ -x /sbin/restorecon ] && /sbin/restorecon /var/cache/yum /var/tmp >/dev/null 2>&1
   112  
   113  if [ -n "$configdone" ]; then
   114    exit 0
   115  fi
   116  
   117  # add fedora user with no passwd
   118  action "Adding live user" useradd $USERADDARGS -c "Live System User" liveuser
   119  passwd -d liveuser > /dev/null
   120  usermod -aG wheel liveuser > /dev/null
   121  
   122  # Remove root password lock
   123  passwd -d root > /dev/null
   124  
   125  # turn off firstboot for livecd boots
   126  systemctl --no-reload disable firstboot-text.service 2> /dev/null || :
   127  systemctl --no-reload disable firstboot-graphical.service 2> /dev/null || :
   128  systemctl stop firstboot-text.service 2> /dev/null || :
   129  systemctl stop firstboot-graphical.service 2> /dev/null || :
   130  
   131  # don't use prelink on a running live image
   132  sed -i 's/PRELINKING=yes/PRELINKING=no/' /etc/sysconfig/prelink &>/dev/null || :
   133  
   134  # turn off mdmonitor by default
   135  systemctl --no-reload disable mdmonitor.service 2> /dev/null || :
   136  systemctl --no-reload disable mdmonitor-takeover.service 2> /dev/null || :
   137  systemctl stop mdmonitor.service 2> /dev/null || :
   138  systemctl stop mdmonitor-takeover.service 2> /dev/null || :
   139  
   140  # don't enable the gnome-settings-daemon packagekit plugin
   141  gsettings set org.gnome.settings-daemon.plugins.updates active 'false' || :
   142  
   143  # don't start cron/at as they tend to spawn things which are
   144  # disk intensive that are painful on a live image
   145  systemctl --no-reload disable crond.service 2> /dev/null || :
   146  systemctl --no-reload disable atd.service 2> /dev/null || :
   147  systemctl stop crond.service 2> /dev/null || :
   148  systemctl stop atd.service 2> /dev/null || :
   149  
   150  # Mark things as configured
   151  touch /.liveimg-configured
   152  
   153  # add static hostname to work around xauth bug
   154  # https://bugzilla.redhat.com/show_bug.cgi?id=679486
   155  echo "localhost" > /etc/hostname
   156  
   157  # Fixing the lang install issue when other lang than English is selected . See http://bugs.centos.org/view.php?id=7217
   158  /usr/bin/cp /usr/lib/python2.7/site-packages/blivet/size.py /usr/lib/python2.7/site-packages/blivet/size.py.orig
   159  /usr/bin/sed -i "s#return self.humanReadable()#return self.humanReadable().encode('utf-8')#g" /usr/lib/python2.7/site-packages/blivet/size.py
   160  
   161  
   162  
   163  # disable updates plugin
   164  cat >> /usr/share/glib-2.0/schemas/org.gnome.settings-daemon.plugins.updates.gschema.override << FOE
   165  [org.gnome.settings-daemon.plugins.updates]
   166  active=false
   167  FOE
   168  
   169  # Show the system-config-keyboard tool on the desktop
   170  mkdir /home/liveuser/Desktop -p >/dev/null
   171  cat /usr/share/applications/system-config-keyboard.desktop | sed '/NotShowIn/d' |sed 's/Terminal=false/Terminal=true/' > /home/liveuser/Desktop/system-config-keyboard.desktop
   172  cat /usr/share/applications/liveinst.desktop | sed '/NoDisplay/d' > /home/liveuser/Desktop/liveinst.desktop 
   173  chmod +x /home/liveuser/Desktop/*.desktop
   174  chown -R liveuser:liveuser /home/liveuser
   175  
   176  # Liveuser face
   177  if [ -e /usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png ] ; then
   178      cp /usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png /home/liveuser/.face
   179      chown liveuser:liveuser /home/liveuser/.face
   180  fi
   181  
   182  # make the installer show up
   183  if [ -f /usr/share/applications/liveinst.desktop ]; then
   184    # Show harddisk install in shell dash
   185    sed -i -e 's/NoDisplay=true/NoDisplay=false/' /usr/share/applications/liveinst.desktop 
   186    # need to move it to anaconda.desktop to make shell happy
   187    #cp /usr/share/applications/liveinst.desktop /usr/share/applications/anaconda.desktop
   188  fi
   189    cat >> /usr/share/glib-2.0/schemas/org.gnome.shell.gschema.override << FOE
   190  [org.gnome.shell]
   191  favorite-apps=['liveinst.desktop','firefox.desktop', 'evolution.desktop', 'empathy.desktop', 'rhythmbox.desktop', 'shotwell.desktop', 'libreoffice-writer.desktop', 'nautilus.desktop', 'gnome-documents.desktop', 'anaconda.desktop']
   192  FOE
   193  
   194  
   195  # set up auto-login
   196  cat > /etc/gdm/custom.conf << FOE
   197  [daemon]
   198  AutomaticLoginEnable=True
   199  AutomaticLogin=liveuser
   200  FOE
   201  
   202  # Turn off PackageKit-command-not-found while uninstalled
   203  if [ -f /etc/PackageKit/CommandNotFound.conf ]; then
   204    sed -i -e 's/^SoftwareSourceSearch=true/SoftwareSourceSearch=false/' /etc/PackageKit/CommandNotFound.conf
   205  fi
   206  
   207  # make sure to set the right permissions and selinux contexts
   208  chown -R liveuser:liveuser /home/liveuser/
   209  restorecon -R /home/liveuser/
   210  
   211  # Fixing default locale to us
   212  localectl set-keymap us
   213  localectl set-x11-keymap us

ipython == 5.1へアップデート後、エラーが起きた時、

centos python

ipython をアップデート後、ipythonを起動すると、ImportErrorが発生して動作しなくなった。ipythonとbackports.shutil_get_terminal_sizeをインストールし直すことで、解決出来た。

> ipython
Traceback (most recent call last):
  File "/bin/ipython", line 7, in <module>
    from IPython import start_ipython
  File "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
    from .core.application import Application
  File "/usr/lib/python2.7/site-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/usr/lib/python2.7/site-packages/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "/usr/lib/python2.7/site-packages/IPython/core/ultratb.py", line 121, in <module>
    from IPython.utils.terminal import get_terminal_size
  File "/usr/lib/python2.7/site-packages/IPython/utils/terminal.py", line 30, in <module>
    from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
ImportError: No module named shutil_get_terminal_size
> sudo pip uninstall ipython backports.shutil_get_terminal_size 
Uninstalling backports.shutil-get-terminal-size-1.0.0:
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/DESCRIPTION.rst
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/INSTALLER
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/METADATA
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/RECORD
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/WHEEL
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/metadata.json
  /usr/lib/python2.7/site-packages/backports.shutil_get_terminal_size-1.0.0.dist-info/top_level.txt
  /usr/lib/python2.7/site-packages/backports/__init__.py
  /usr/lib/python2.7/site-packages/backports/__init__.pyc
  /usr/lib/python2.7/site-packages/shutil_backports/__init__.py
  /usr/lib/python2.7/site-packages/shutil_backports/__init__.pyc
  /usr/lib/python2.7/site-packages/shutil_backports/get_terminal_size.py
  /usr/lib/python2.7/site-packages/shutil_backports/get_terminal_size.pyc
Proceed (y/n)? y
  Successfully uninstalled backports.shutil-get-terminal-size-1.0.0
> sudo pip install ipython backports.shutil_get_terminal_size 
Collecting ipython
  Using cached ipython-5.1.0-py2-none-any.whl
Collecting backports.shutil_get_terminal_size
  Using cached backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): pygments in /usr/lib64/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): decorator in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): traitlets>=4.2 in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): setuptools>=18.5 in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pexpect; sys_platform != "win32" in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): prompt-toolkit<2.0.0,>=1.0.3 in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pathlib2; python_version == "2.7" or python_version == "3.3" in /usr/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): ipython-genutils in /usr/lib/python2.7/site-packages (from traitlets>=4.2->ipython)
Requirement already satisfied (use --upgrade to upgrade): enum34; python_version == "2.7" in /usr/lib/python2.7/site-packages (from traitlets>=4.2->ipython)
Requirement already satisfied (use --upgrade to upgrade): six in /usr/lib/python2.7/site-packages (from traitlets>=4.2->ipython)
Requirement already satisfied (use --upgrade to upgrade): ptyprocess>=0.5 in /usr/lib/python2.7/site-packages (from pexpect; sys_platform != "win32"->ipython)
Requirement already satisfied (use --upgrade to upgrade): wcwidth in /usr/lib/python2.7/site-packages (from prompt-toolkit<2.0.0,>=1.0.3->ipython)
Installing collected packages: backports.shutil-get-terminal-size, ipython
Successfully installed backports.shutil-get-terminal-size-1.0.0 ipython-5.1.0
> ipython
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: