Excel VBAでシートの存在有無を判定する場合にループ使うのは冗長だなーと思ったのだが、実はOn Errorステートメントを使うとすっきりと書けた、という話。
元ネタはExcel VBA If WorkSheet(“wsName”) Exists - Stack Overflow
続きを読むExcel VBAでシートの存在有無を判定する場合にループ使うのは冗長だなーと思ったのだが、実はOn Errorステートメントを使うとすっきりと書けた、という話。
元ネタはExcel VBA If WorkSheet(“wsName”) Exists - Stack Overflow
続きを読む日常的にワイルドカードを使っているくせにちゃんと名前を知らなかったんだなあ、というメモ。
ワイルドカードってのはls *.txt
のようなやつ。
文字列に ‘?’, ‘*’, ‘[’ が含まれていると、 それはワイルドカードパターンとみなされる。 「glob する」というのは、ワイルドカードパターンを展開して、 そのパターンにマッチするパス名のリストを得ることである。
出典: Man page of GLOB
glob (programming) - Wikipedia)*1
自前の仮想マシン(CentOS7)にsshしようとしたら、そもそもLinkUPしてなかったので、とりあえずNICを自動起動に設定したメモ*1*2
#NICの開始 [root@localhost ~]# nmcli dev connect eno16777736 Device 'eno16777736' successfully activated with '314879d4-8571-4178-8874-6f1dea2bcc32' #自動起動を有効に [root@localhost ~]# nmcli con mod eno16777736 connection.autoconnect yes #以下で自動起動にならないのはなぜなんだ… #nmcli device set ifname eno16777736 autoconnect yes #設定の確認 [mk55@localhost ~]$ nmcli con show eno16777736 | grep autoconnect connection.autoconnect: yes connection.autoconnect-priority: 0 connection.autoconnect-slaves: -1 (default)
2.3. NetworkManager のコマンドラインツール nmcli の使用
オフィシャルのドキュメントなのでそれなりに参考になる。
全然知らなかったけど、RHEL7ではNICのネーミングルールが「Predictable Network Interface Names」変わっていて、イーサネット(オンボード)はenoで表示されるそうだ。
script
で取得したログにエスケープシーケンス含まれる場合、単純なテキストとして読むとエスケープシーケンスがESC~のような表示されてしまい読みづらい。
が、less -R
で読むと綺麗に読める。
scriptなどでログを取るときに変な文字(制御文字)のない状態で読めるようにする - Qiita 元ネタは上記の記事
[mk55@localhost ~]$ powerofESC[ESC[ESC[ESC[ESC[ESC[ESC[ESC[K^G^G^G^G^G^G^G^G^G^G^GnmclESC[ESC[KllESC[ESC[Ki ESC[32mvirbr0: connected to virbr0ESC[0m bridge, 52:54:00:A1:4E:6E, sw, mtu 1500 inet4 192.168.122.1/24 ESC[31meno16777736: disconnectedESC[0m "Intel 82545EM Gigabit Ethernet Controller (Copper) (PRO/1000 MT Single Port Adapter)" 1 connection available ethernet (e1000), 00:0C:29:53:02:5E, hw, mtu 1500 ESC[2mlo: unmanagedESC[0m loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536 ESC[2mvirbr0-nic: unmanagedESC[0m tun, 52:54:00:A1:4E:6E, sw, mtu 1500
Script started on Sun 21 May 2017 01:07:50 AM JST [mk55@localhost ~]$ ^G^G^G^G^G^G^G^G^G^G^Gnmcli virbr0: connected to virbr0 bridge, 52:54:00:A1:4E:6E, sw, mtu 1500 inet4 192.168.122.1/24 eno16777736: disconnected "Intel 82545EM Gigabit Ethernet Controller (Copper) (PRO/1000 MT Single Port Adapter)" 1 connection available ethernet (e1000), 00:0C:29:53:02:5E, hw, mtu 1500 lo: unmanaged loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536 virbr0-nic: unmanaged tun, 52:54:00:A1:4E:6E, sw, mtu 1500
なお、上記ではシンタックスハイライトが効いてしまってわからなくなっているが、less -R
だとカラーエスケープシーケンスも理解して、ちゃんと画面表示に色がつく(lessの場合は単純な白黒表示)。
CentOS7などのsystemを利用するOSでデフォルトログイン方法をCUIに変えるにはディスプレイマネージャを無効にすればよい。
[root@localhost updates]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
サービスの有効化を確認(2通り)
[root@localhost updates]# systemctl list-unit-files | grep gdm.service gdm.service enabled [root@localhost updates]# systemctl is-enabled gdm.service enabled
サービスの起動状態を含めて確認
[root@localhost updates]# systemctl status gdm.service ● gdm.service - GNOME Display Manager Loaded: loaded (/usr/lib/systemd/system/gdm.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2017-05-06 10:26:23 JST; 2h 32min ago Process: 1013 ExecStartPost=/bin/bash -c TERM=linux /usr/bin/clear > /dev/tty1 (code=exited, status=0/SUCCESS) Main PID: 934 (gdm) CGroup: /system.slice/gdm.service ├─ 934 /usr/sbin/gdm └─1042 /usr/bin/Xorg :0 -background none -noreset -audit 4 -verbose -auth /r... May 06 10:26:23 localhost.localdomain systemd[1]: Starting GNOME Display Manager... May 06 10:26:23 localhost.localdomain systemd[1]: Started GNOME Display Manager. May 06 10:27:40 localhost.localdomain gdm[934]: Child process -2639 was already dead.
デフォルトのGDM(GNOME Display Manager)が有効になっている。
サービスの無効化
[root@localhost updates]# systemctl disable gdm.service Removed symlink /etc/systemd/system/display-manager.service.
サービスが無効なことを確認(2通り)
[root@localhost updates]# systemctl list-unit-files | grep gdm.service gdm.service disabled [root@localhost updates]# systemctl is-enabled gdm.service disabled
サービスの起動状態も含めて確認
[root@localhost updates]# systemctl status gdm.service ● gdm.service - GNOME Display Manager Loaded: loaded (/usr/lib/systemd/system/gdm.service; disabled; vendor preset: enabled) Active: inactive (dead) Main PID: 934 CGroup: /system.slice/gdm.service ├─ 934 /usr/sbin/gdm └─1042 /usr/bin/Xorg :0 -background none -noreset -audit 4 -verbose -auth /r... May 06 10:26:23 localhost.localdomain systemd[1]: Starting GNOME Display Manager... May 06 10:26:23 localhost.localdomain systemd[1]: Started GNOME Display Manager. May 06 10:27:40 localhost.localdomain gdm[934]: Child process -2639 was already dead.
GDMが無効化された。
なおこの時点では起動しているGDMGUIが停止するわけではない(GUI表示のまま)。
再起動(reboot
)するとCUIログインに切り替わる
なお、rebootコマンドはLinux以外のUnixだと危険なコマンドらしい。
Linuxについては、Man page of SHUTDOWNにあるように、rebootはshutdown -r -q nowのエイリアスです(シェルのエイリアスというわけではなく、内部でshutdown -r -q nowを呼び出しているだけと言うこと)。shutdownと同じくinitシステムを6に切り替えるため、サービスを順番に落とし(最新のLinuxではsystemdやupstartが採用される場合が多いですが、同じように順番にサービスを落とします)、再起動を行います。サービスが依存関係に基づいた安全な順序でおとされ、各終了処理も実行されますので、shotdownを使う場合と同じく、安全に再起動が可能です。
しかし、LinuxではないUNIXでは違います。次の二つを見てください。
FreeBSD 11.0 | On-line Manual of “reboot”
Solaris 11.2 | reboot - マニュアルページセク ション 1M: システム管理コマンド
FreeBSDとSolarisでは、shutdownへのエイリアスででも呼び出す物でもありません。これらのrebootでは、initシステムの切り替えが発生せず、全てのプロセスに対して終了シグナルを送るだけです。サービスの終了順序は守られませんし、initスクリプトに記載された終了時の処理も行われません。そのため、サービスによってはテンポラリファイルやPIDファイルが残ったり、エラーが記録されたり、最後の情報が書き込まれなかったり等の不具合が起きる可能性があります
CentOSでyum update
時に”Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast”というメッセージが出ることがある
yum claen all
しろというサイトもあるが、エラーメッセージの通り、素直にyum makecache fast
しましょう
案件が変わってちょっと自宅で自習したくなり、昔に作ったCentOSのVMをアップデートしようとしたら以下のメッセージが出た
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
ググってみるとyumのキャッシュの問題らしく、キャッシュをyum claen all
してクリアすればよいらしい。
で、実際にyum claen all
してからyum update
すると無事にアップデートはできた。
が、しかし、メッセージをよく読むとyum makecache fast
しろって書いてある*2。
そこでちょっとmanを読んでみる(長いので読み飛ばしてもOK)。
yum(8) yum(8) NAME yum - Yellowdog Updater Modified (中略) clean Is used to clean up various things which accumulate in the yum cache directory over time. More complete details can be found in the Clean Options section below. makecache Is used to download and make usable all the metadata for the currently enabled yum repos. If the argument "fast" is passed, then we just try to make sure the repos. are current (much like "yum clean expire-cache"). (中略) CLEAN OPTIONS The following are the ways which you can invoke yum in clean mode. Note that "all files" in the commands below means "all files in currently enabled repositories". If you want to also clean any (temporarily) disabled repositories you need to use --enablerepo='*' option. yum clean expire-cache Eliminate the local data saying when the metadata and mir‐ rorlists were downloaded for each repo. This means yum will revalidate the cache for each repo. next time it is used. How‐ ever if the cache is still valid, nothing significant was deleted. yum clean packages Eliminate any cached packages from the system. Note that pack‐ ages are not automatically deleted after they are downloaded. yum clean headers Eliminate all of the header files, which old versions of yum used for dependency resolution. yum clean metadata Eliminate all of the files which yum uses to determine the remote availability of packages. Using this option will force yum to download all the metadata the next time it is run. yum clean dbcache Eliminate the sqlite cache used for faster access to metadata. Using this option will force yum to download the sqlite metadata the next time it is run, or recreate the sqlite metadata if using an older repo. yum clean rpmdb Eliminate any cached data from the local rpmdb. yum clean plugins Tell any enabled plugins to eliminate their cached data. yum clean all Does all of the above.
とても雑にまとめると以下の表のとおり。
yum clean all
は余計なキャッシュデータも消してしまっているので、yum makecache fast
を使ってキャッシュを更新する方が好ましいのだと思う。
# | コマンド | 説明 |
---|---|---|
1 | yum clean all |
現在利用可能なレポジトリの すべてのキャッシュを削除する*3 |
2 | yum makecache fast |
現在利用可能なレポジトリを確認して キャッシュの一部を更新する*4 |
manを読んでyumの正式名称を初めて知った Yellowdog Updater Modified - Wikipedia
トリプルクリックすると行選択される。