間違いだらけの備忘録

このページの内容は無保証でありこのページの内容によって直接、または間接に損害を受けられたとしても私は責任を取りません。

bash

ログイン時の自動screenなど

~$ cat .bash_profile find ~/screen.log/ -mtime +30 -print0 | xargs -0 rm -rf & #disabling_gnu_screen_lock_screen export LOCKPRG='/bin/true' read -t 10 -p "Hit ENTER or wait ten seconds" || screen -r -d -U || screen -U参考: stackoverflow.co…

シェルスクリプトのlintツール

https://www.shellcheck.net/#

リターンコード-1が255になる

$ cat exitcodetest.c int main() { return -1; } $ gcc exitcodetest.c $ ./a.out $ echo $? 255https://unix.stackexchange.com/questions/37915/why-do-i-get-error-255-when-returning-1 UNIX/POSIX, the exit code of a program is defined to be an un…

bash ステップ実行

https://blog.sgnet.co.jp/2016/07/bashbash.html #!/bin/bash trap 'read -p "$0($LINENO) $BASH_COMMAND"' DEBUGめも

セキュリティ

https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/ $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"素敵〜 https://x86-64.jp/blog/CVE-2014-6271 もうちょっとゾクッ…

カレントディレクトリのみのプロンプトに修正

http://d.hatena.ne.jp/InoHiro/20091111/1257916537 「\u」がユーザー名、「\h」がコンピュータ名?、「\w」(小文字)がPWDのようなので、これを「\W」(大文字, カレントディレクトリのみ)に変更。 めも、未検証

bashrcの設定の読み込まれる順番

http://takuya-1st.hatenablog.jp/entry/20110102/1293970212 めも、未検証

多重起動の防止

http://blog.bsdhack.org/index.cgi/Computer/20120621.html # Check single run start # http://blog.bsdhack.org/index.cgi/Computer/20120621.html lockfile=${TMP:-/tmp}/${0##*/} while true do if ln -s $$ ${lockfile} 2> /dev/null then break else …

シェルスクリプトを書くときに

http://d.hatena.ne.jp/masudaK/20120223/1330006586 http://d.hatena.ne.jp/mikeda/20120226/1330250904 めもunary operator expected if [ $var = "abc" ];thenちゃんとクオートしましょう。 if [ "$var" = abc ];then # 逆にabcはクオートしなくてもいい…

bashdb

http://packages.debian.org/ja/wheezy/bashdb ステップ実行可能 http://www.itmedia.co.jp/enterprise/articles/0812/04/news060.html http://dharry.hatenablog.com/entry/20111108/1320690055 リファレンス http://bashdb.sourceforge.net/bashdb.html#De…

標準入力の差し替え

http://linux.just4fun.biz/逆引きシェルスクリプト/設定でstdout,stderrの出力先をファイルにする.html exec 2>> stderr.log 1>> stdout.log保存と復帰 参考 Bashクックブック ISBN:9784873113760 exec 3>&1 exec 1> /tmp/aaa.log echo exec 1>&3-めも

Apache CGIでメール送信

# cat /usr/lib/cgi-bin/hoge #!/bin/bash if [ -n "$HTTP_HOST" ] ; then echo -e "Content-Type: text/html; charset=UTF-8\r\nPragma: no-cache\r\nCache-Control: no-cache, must-revalidate\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n\r\n" fi rea…

シェルスクリプト Tips

http://funini.com/kei/unix/sh.shtml めも、未検証

特殊変数

http://d.hatena.ne.jp/shibainu55/20081129/1227976178 $? $! $- $$:コマンド自身の PID (プロセスID)が設定される変数(中略)変数 $$ を拡張子に指定することで、シェルスクリプト実行毎に作成するファイル名を変えることができるので、 同一シェルスクリプ…

ファイル・ディレクトリ名の一括置換/一括作成

http://uguisu.skr.jp/Windows/find_xargs2.html サブディレクトリに渡る拡張子のないすべてのファイルに拡張子を付ける $ find . -type f ! -name "*.*" -exec mv '{}' '{}.bak' \;めも

配列処理

http://d.hatena.ne.jp/nattou_curry_2/20091104/1257346587#array5 めも

プロセスが終了したら通知

shredが終わったらCDトレイで通知 # while (pgrep shred) do sleep 60 ; done ; eject -TCD-ROMドライブ(eject)ユーザー会 http://d.hatena.ne.jp/Akkiesoft/searchdiary?word=eject めも

bashヒストリの編集

http://oshiete.goo.ne.jp/qa/1338332.html bashヒストリの書き込み $ history -w bashヒストリの編集 $ vi ~/.bash_history bashヒストリの読み込み $ history -rめも

直前に入力したコマンドの最後の引数を補完

http://d.hatena.ne.jp/lurker/20061004 Esc + ドット(.) と入力すると、 直前に入力したコマンドの最後の引数を補完してくれる。 http://d.hatena.ne.jp/Hash/20090927/commandlinehistory !! 直前に実行したコマンドを再現 !文字列 !:s/foo/bar めも

ヒストリのインクリメンタルサーチ

http://thethirdshuren.org/blog/shell/bash_incsearch.htm 使いかたは、コマンドラインから「Ctrl+r」。すると、プロンプトが↓のように変わり、 (reverse-i-search)`':文字を入力するとヒストリを検索してくれる。 一致する履歴が複数ある場合は、「Ctrl+r…

標準エラー出力

http://x68000.q-e-d.net/~68user/unix/pickup?%A5%EA%A5%C0%A5%A4%A5%EC%A5%AF%A5%C8 標準出力と標準エラー出力を両方まとめて他のコマンドに渡すには % command 2>&1 | lessとし、標準出力と標準エラー出力をまとめて file に書き出す場合は % command >fi…

デーモン化

bashクックブック ISBN:9784873113760 P216 nohup hoge.sh 0<&- 1>/dev/null 2>&1 &標準入出力を切り離しているので、最低限にはなるようだ。http://oshiete1.watch.impress.co.jp/qa1059932.html Linuxの標準シェルであるbashの場合、&するだけで制御端末も…

文字列比較のTips

http://www.ibm.com/developerworks/jp/linux/library/l-bash2.html string1 =string2 string1 とstring2 が等しい場合に真 [ "$myvar" = "one two three" ] string1 !=string2 string1 とstring2 が等しくない場合に真 [ "$myvar" != "one two three" ]めも

デバッグ

http://www.geocities.jp/geo_sunisland/debug.html 「-v」オプションは、シェルスクリプト内でこれから実行されるコマンドを表示する。変数が使用されている場合は「-x」オプションとは異なり、変数名がそのまま表示される。 set -xによる部分debug # デバ…

if文中になにも無いと下記エラー syntax error near unexpected token `fi' `fi' 参考 http://ozuma.txt-nifty.com/blog/2008/12/shif-98f6.html ちなみに、どうしても空のif文を作りたければ、builtin(1)で用意されているヌルコマンド : を使えば良い。コロ…

ファイルリネームスクリプト

http://www.linux.or.jp/JF/JFdocs/Bash-Prog-Intro-HOWTO-12.html bash -x ~/bin/renna.sh p D_ *.JPG 2>> /tmp/rename.log

IPアドレスの取得

LANG=C ifconfig eth0 | grep "inet addr" | awk '{print $2}' | sed 's/addr://'http://www.atmarkit.co.jp/flinux/rensai/iptables04/iptables03g.html めもhttp://d.hatena.ne.jp/gunshot/20080804より長いが分かりやすい。 LANG=C ifconfig eth0 | sed -…

bashの補完機能を拡張

http://ubulog.blogspot.com/2007/10/bash.html めも 未検証ctrl-cをbash script内で捕捉する http://www.himajin2001.com/wiki.cgi?page=%B5%BB%BD%D1%C5%AA%BB%A8%C3%CC%2Dctrl%2Dc%A4%F2script%C6%E2%A4%C7%CA%E1%C2%AA%A4%B9%A4%EB#p10 #!/bin/sh trap '…

timeコマンドの出力をリダイレクト

$ (time command) >& foo.log $ (time command) 2>&1 | tee foo.log参考 http://blog.livedoor.jp/hack_cripple/archives/50800592.html

bashでの確認問い合わせ

dialogが使えない環境用 http://yuki.silk.to/2006/04/000161.html http://ubuntuforums.org/showthread.php?t=531144 めも

このページにはhatena以外のサービスからのコンテンツが埋め込まれています。 hatenaによりGoogle AdSense 広告が埋め込まれています。