Shammer's Philosophy

My private adversaria

ShellScript

Invoke some script when system shutdown on Mac OS X

What I would like to do I found How can I use launchd to run logout script | Discussion | Jamf Nation, and the way posted at 10/30/15 7:05 PM by Bruienne sounds good. His idea is invoking some script as a LaunchAgent which uses trap comman…

${OSTYPE} returns blank

I understood that SHELL value OSTYPE returns the platform indicating current operating system. Then, I used this in my shell script but $OSTYPE always blank in my shell script even if $OSTYPE has a not blank value in Terminal. My script in…

Bash Shell Script my pocket reference - 20160316

Updated from Bash Shell Script my pocket reference - 20151206 - Shammerism. Added the way how to check if the valuable is not blank and others. if 文 sample if basic if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];t…

Waiting until network enabled

If I have something to do when the host launched and it requires network, I have to consider that network access not prepared when the something invoked. It is useful to wait network preparation completed. This is a sample. while true; do …

CLI command execution automation

I wrote an article about sshpass as Automate the operation started from ssh login - Shammerism, but I found an easier way. Step is below. Create a file written in the CLI commands which I would like to execute cat $ABOVE_FILE | sshpass -p …

Change character encoding to UTF-8

This is an second version of 文字コードをまとめて変換するスクリプト - Shammerism. The before article handles multiple files at one time, but this version handles only 1 file. #!/bin/bash NKF_CHECK=`which nkf | wc | awk '{print $1}'`; if [ …

How to send long http header requests with curl?

This is a memo for me. $ HEADER="X-Header: X" $ for i in `seq 1 65535`;do HEADER="${HEADER}X";done $ curl -v -H "${HEADER}" http://www.test.local/The parameter should be enclosed with double quote. Without enclosing double quote, curl can …

Bash Shell Script my pocket reference - 20151206

Updated from Bash Shell Script my pocket reference - 20150923 - Shammerism. Added the way how to use array on bash. if 文 sample if basic if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are number#1."…

Read string from STDIN on shell

There is a command line tool whose name is read. This enables to read a string from STDIN. This requires several aruguments, and those arguments are used to save strings from STDIN. This is a sample. echo "What is ticket name?"; read NAME;…

Automate the operation started from ssh login

I would like to automate the CLI operation started from ssh login. This may be a useful if you would like to repeat the similar command. This can be come true with sshpass. Here is a sample. for i in `seq 1 10`;do (echo "somecommand 1";ech…

ファイル名一括変換スクリプト

大量ファイル一括編集スクリプト - Shammerismでは、ファイルの中身を一括で書き変えるスクリプトを書いたが、ファイル名を書き変えるスクリプト。 if [ -e targets ];then rm targets; fi ls -l $1 | awk '{print $9}' > targets; while read file do mv $f…

Bash Shell Script my pocket reference - 20150923

Bash Shell Script Collection - 20150512 - ShammerismとBash Shell Script my pocket reference - 20150910 - Shammerismをマージ。 if 文 sample if basic if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are …

Bash Shell Script my pocket reference - 20150910

Bash Shell Script my pocket reference - 20150221 - Shammerismの内容に、ファイルの存在を確認する方法を追加。 if 文 sample if basic if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are number#1."; elif […

Bash Shell Script Collection - 20150512

Bash Shell Script my pocket reference - 20150221 - Shammerismの内容に、大文字と小文字を無視して比較する方法を追加。 if 文 sample if basic if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are number#1."…

Bash Shell Script my pocket reference - 20150221

Bash Shell Script my pocket reference - 20150217 - Shammerismの内容に、ifのandとorの指定方法を追加。 if 文 sample if basic if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are number#1."; elif [ $1 -eq…

Bash Shell Script my pocket reference - 20150217

Bash Shell Script my pocket reference - 20150213 - Shammerismの内容にBash 終了判定 - Shammerismの内容を追記。こんな記事書いていたんだと思った。。。 if 文 sample if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then e…

Bash Shell Script my pocket reference - 20150213

Bash Shell Script my pocket reference - 20120813 - Shammerismの続編。前回書いてからもいろいろ書いているが全然まとめていない。。。ひょんなことから、同一ディレクトリ内の全てのファイルに同様の接頭辞をつけるような名前変更をやったが、数が多いと…

bash_profile aliases

I use tshark command for analyzing captured packets. But this command output has no time-format. My favorite option of tshark time-format is "-t ad", but it is boring to add this option every time. I add the alias to $HOME/.bash_profile as…

How to get html required authentication by curl?

The command "curl" has a -c option and -b option. The option -c makes cookie filed into local disk. And the option -b is used the cookie file to connect web server. Then, the option -d enables to send post data. So, the following steps ena…

Bash 終了判定

シェルスクリプトの終了ステータスは、$? に格納されるはずだが、いちいちこれを if で比較判定するの面倒だな、と思っていたら、もっと簡単に実行する方法が見つかった。 終了ステータス | UNIX & Linux コマンド・シェルスクリプト リファレンスうーん、こ…

大量ファイル一括編集スクリプト

非常に多くのテキストファイルの一部のみ変更したい、そんな場合に使うスクリプトを書いた。流れとしては、 編集対象ファイルのあるディレクトリをリストアップ そのディレクトリ内のファイルにある編集したい文字をsedで置換 というシンプルなものだが、念…

文字コードをまとめて変換するスクリプト

仕事でとあるログを確認することがあるのだが、そのログがなぜかUTF-16LEで書かれている。UTF-16LEだと、cygwinのgrepで引っかかってくれないので、iconv を使って1つずつUTF-8に変換していたが、数が多いとやってられない。そこで過去(2008/07/31)に作成し…

shellだけで非同期処理を行えるか?

どうやら、wait というコマンドと trap というコマンドがあるらしい。 端末のシェル(bash,dash,zsh,csh系)におけるwaitコマンドについて - 試験運用中なLinux備忘録 【 trap 】 システム割り込み時の処理を設定する | 日経 xTECH(クロステック) wait使用例…

Bashの$!

bashには、いろいろな変数があるが、また新しく一つ知ったのでそれを備忘メモ。最後に実行したback ground process の PID が格納される$!。以下、実行例。 $ sleep 5 & [2] 1779 $ [2]- Done sleep 5 $ echo $! 1779 $ sleep 30 & [2] 1796 $ echo $! 1796 …

cut を awk のように使う?

タブやスペースなどを含む行から、そのタブやスペースで区切られた形で行を複数の文字列に分割するときに awk を使っていたが、cut でも同様のことができるとわかったのでメモ。 $ cut -d "_" -f 1-2この例だと、ホワイトスペースでなく _ で行の文字を分割…

Bash Shell Script my pocket reference - 20120813

Bash Shell Script my pocket reference - 20100812 - Shammerismの続編。条件の否定と、シェルでの文字列操作-20120805 - Shammerismの内容をマージ。 if 文 sample if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "Y…

シェルでの文字列操作-20120805

あると思っていたがなかった(見つけられなかった?)ので書くことにしました。抜き出しや長さ判定はもっと良さそうなのがあるかもしれないけれども。 Equal判定 if [ $VALUE = "0" ];then echo "VALUE is 0"; else echo "VALUE is not 0"; fi 空文字判定 if [ …

ShellScript条件分岐ーif文-20120109

ShellScript条件分岐ーif文-20101010 - Shammerismに条件の and と or を追加。 #!/bin/bash echo "IF example!"; if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi # # Compare numbers # if [ $1 -eq 1 ];then echo "You are number#1."; elif [ …

ShellScript条件分岐ーif文-20101010

ShellScript条件分岐ーif文-20100921 - Shammerismのアップデート版。ファイルの比較を追加。 #!/bin/bash echo "IF example!"; if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi # # Compare numbers # if [ $1 -eq 1 ];then echo "You are number…

ShellScript条件分岐ーif文-20100921

ShellScript条件分岐ーif文 - Shammerismのアップデート版。文字列の比較を追加。 #!/bin/bash echo "IF example!"; if [ $# -ne 1 ];then echo "Usage: $0 [123]"; exit 1; fi if [ $1 -eq 1 ];then echo "You are number#1."; elif [ $1 -eq 2 ];then echo…