Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

teeコマンドで標準出力に文字だしつつ、別のファイルにも内容をキープしておく

$ printf "val=%05d\n" 30 | tee hoge.txt
val=00030

$ cat hoge.txt 
val=00030
|

"-a"オプションをつけると上書き禁止でもりもり文末にくっついていきます。

$ cat hoge.txt 
val=00030

$ printf "val=%05d\n" 99 | tee -a hoge.txt
val=00099

$ cat hoge.txt 
val=00030
val=00099

逆に、一からやり直したい場合はオプションなしで。

$ cat hoge.txt 
val=00030
val=00099

$ printf "val=%05d\n" 100 | tee hoge.txt
val=00100

$ cat hoge.txt 
val=00100

curlコマンドで標準入力の結果を受け取る

curlコマンドはPOSTアクションを実行できます。
これを使って簡易な投稿のシステムを作る時、標準入力の結果を受け取る事ができると便利ですよね。
今回はその方法について。

実際のこころ

文字列"SOMETHING"をcurlでYOUR_DISTに送る場合、以下のようにします。

$ echo "SOMETHING" | curl YOUR_DIST -X POST -d @-

"@-"が標準入力を受け取るとこですね。

"@FILENAME"とすると、ファイルの中身を送信することもできます。

XWindow環境(i3など)で"Fatal server error: could not open default font 'fixed'"と出たら……フォントの入れ忘れかも

XWindow環境(i3など)で"Fatal server error: could not open default font 'fixed'"と出たら……フォントの入れ忘れかもしれません。

実際おtころ

環境を再構築していた時のこと……。

$ vncserver :1 -geometry 1280x800 -depth 24
Couldn't start Xtightvnc; trying default font path.
Please set correct fontPath in the vncserver script.
Couldn't start Xtightvnc process.

23/11/18 08:11:16 Xvnc version TightVNC-1.3.9
23/11/18 08:11:16 Copyright (C) 2000-2007 TightVNC Group
23/11/18 08:11:16 Copyright (C) 1999 AT&T Laboratories Cambridge
23/11/18 08:11:16 All Rights Reserved.
23/11/18 08:11:16 See http://www.tightvnc.com/ for information on TightVNC
23/11/18 08:11:16 Desktop name 'X' (linaro-alip:1)
23/11/18 08:11:16 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
23/11/18 08:11:16 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/X11/misc/' not found - ignoring
Font directory '/usr/share/fonts/X11/Type1/' not found - ignoring
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring

Fatal server error:
could not open default font 'fixed'
23/11/18 08:11:17 Xvnc version TightVNC-1.3.9
23/11/18 08:11:17 Copyright (C) 2000-2007 TightVNC Group
23/11/18 08:11:17 Copyright (C) 1999 AT&T Laboratories Cambridge
23/11/18 08:11:17 All Rights Reserved.
23/11/18 08:11:17 See http://www.tightvnc.com/ for information on TightVNC
23/11/18 08:11:17 Desktop name 'X' (linaro-alip:1)
23/11/18 08:11:17 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
23/11/18 08:11:17 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/X11/misc/' not found - ignoring
Font directory '/usr/share/fonts/X11/Speedo/' not found - ignoring
Font directory '/usr/share/fonts/X11/Type1/' not found - ignoring
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring

Fatal server error:
could not open default font 'fixed'

エラーをみると、どうもフォント周りのようなので

$ sudo apt install xfonts-base
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  xfonts-encodings xfonts-utils
The following NEW packages will be installed:
  xfonts-base xfonts-encodings xfonts-utils
0 upgraded, 3 newly installed, 0 to remove and 250 not upgraded.
Need to get 6557 kB of archives.
After this operation, 8380 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

#...

Setting up xfonts-utils (1:7.7+4) ...
Setting up xfonts-base (1:1.0.4+nmu1) ...

これであらためてやると……はい動きました。

$ vncserver :1 -geometry 1280x800 -depth 24

New 'X' desktop is linaro-alip:1

Starting applications specified in /home/linaro/.vnc/xstartup
Log file is /home/linaro/.vnc/linaro-alip:1.log

こういう事は構築に慣れた時ほど見落としがちです。
……なに、Docke? そんなハイカラなもん使えません(逆ギレ

scpコマンドでUNIX系システム間ファイル送信

scpコマンドをつかうと、UNIX系システム間ファイル送信できます。
たとえば、macOS上でセコセコ作っていたC++のコードをRasPiに転送したり……。

manの解説によると以下の通りなので……sshコマンドの仕組みを使ってるようです。

scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1).

実際のところ

接続先が"pi@192.168.0.xxx"だとして……

今いるディレクトリのmain.py

$ scp ./main.py pi@192.168.0.xxx:~/www

直下のwwwのディレクトリを再帰的に

$ scp  -rC ./www pi@192.168.0.xxx:~/www

参考もと

【読書メモ】9割が結果を出す! 小さな会社の脱零細マニュアル

9割が結果を出す! 小さな会社の脱零細マニュアル

9割が結果を出す! 小さな会社の脱零細マニュアル