Help us understand the problem. What is going on with this article?

bash shell に関するtips 備忘録

実行時にデバッグ出力する場合のヘッダ

#!/bin/bash -x

root以外が実行すると処理せずに終了させる

if [ $(whoami) != "root" ]; then
        echo "This script must be run as root"
        exit 1
fi

スペースの入ったファイル名を処理するために配列の分割子を改行コードに固定する

export IFS=$'\n'

ので、上記設定以降はshell内での配列指定は以下の例のように記述する必要がある

EXTLIST=(
"mov"
"mkv"
"..avi"
"avi.mp4"
"wmv.mp4"
"flv.mp4"
"mpeg"
"mpg"
"flv"
"rmvb"
"wmv"
"M4A"
"avi"
"ts")

rootから全てのユーザのjavaに対してgc実行リクエストする

for line in `ps aux | grep java | tr -s " " | grep -v grep | tr " " "," | cut -d ',' -f 1-2`
do
        arr=( `echo $line | tr -s ',' ' '`)
        user=${arr[0]}
        pid=${arr[1]}
        sudo -u $user jmap -histo:live $pid
done

lockファイルを作らずに、shellの複数起動をしないようにする

参考 : https://qiita.com/hit/items/e95298f689a1ee70ae4a

_pcnt=`pgrep -fo ${CMDNAME} | wc -l`               
if [ ${_pcnt} -gt 1 ]; then                        
        echo "This script has been running now. proc : ${_pcnt}"
        exit 1                                           
fi
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした