Changes between Version 1 and Version 2 of jazz/10-07-22
- Timestamp:
- Jul 22, 2010, 4:26:45 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
jazz/10-07-22
v1 v2 1 = 2010-07-22 = 2 3 * [備忘] 重新改用 root 身份執行的 shell script 1 4 {{{ 5 #!sh 2 6 [ "`id -u`" != "0" ] && exec sudo su -c "$0" "$@" 3 7 }}} 8 * [備忘] 讓標準輸出(STDOUT)與標準錯誤(STDERR)導入到 log 檔的 bash script 寫法 4 9 {{{ 10 #!sh 11 #! /bin/bash 12 13 TARGET="target-file" 14 15 # file descriptor 4 prints to STDOUT and to TARGET 16 exec 4> >(while read a; do echo $a; echo $a >>$TARGET; done) 17 18 # now STDOUT is redirected 19 exec >&4 20 exec 2>&4 21 date 22 echo "Date sent to fd4." 23 abc 24 5 25 }}}