シェルスクリプトで変数が空文字であるか調べる

シェルスクリプトで変数に値が入っているか調べるには、testコマンドやif分で変数の値を比較して調べることができます。
testコマンドで変数が空文字であるか調べるtestコマンド ...
ファイルの所有者を監視するスクリプト

PHPでファイルの書込み処理をするプログラムがあって、そのファイルの所有権が「apaceh」以外だとパーミッションエラーとなり書込みが失敗するので、ファイルの所有者がApacheか ...
Cronで日本語のメールを送ると文字化け・添付ファイルになる

日本語の文字列があるメールを送ると添付ファイルなる場合の対処法
件名は日本語でメール本文に日本語文字列があるメールを送信するシェルスクリプトを作って、スクリプトを実行してメールを送信すると受信したメールの件名・本文ともメー ...
while readで最終行が処理されない【シェルスクリプト】

Windowsで生成したファイルをシェルスクリプトでwhile readを利用して、catコマンドでファイルを出力して、内 ...
シェルスクリプトを利用して、iptablesに特定のIPを拒否するスクリプト

iptablesのF/Wで特定のIPアドレスを拒否(DROP)したい場合に、その都度コマンドを入力するのが面倒なので、シェルスクリプトで引数に拒否したいIPアドレ ...
シェルスクリプトで「Enter」を押さないと処理を進めないようにする

シェルスクリプトで処理を進めていて、変数とか処理に問題なければ処理を進めたいケースがあります。その場合に「エンター(Enter)キー」を押すと処理を進める場合は「read Wait」と ...
dateコマンドで、ファイルのタイムスタンプを取得

指定したファイルの日付・時間等のタイムスタンプを取得するには「date」コマンドを使用すれば取得できます
$ ls -l test.txt-rw-rw-r-- 1 centos ce ...Windowsで作成したシェルスクリプトで実行すると、「command not found」エラー

シェルスクリプトを作るときはAtom等のエディタで作ってSCPでアップしていました。macOSからWindowsに変更して ...
関数の呼び出し順で「command not found」のエラー

関数を使ったシェルスクリプトで関数の呼び出す場所は、定義した関数より前に書くと「command not found」や「Main: コマンドが見つかり ...
シェルスクリプトでwhile内のでsshコマンドを使用すると1回しか処理されない

シェルスクリプトでwhile文を利用して、そのループ処理内にsshコマンドを使用するとループ処理されずに1回のみとなる場合の対処方法です
下記のシェルスクリプトでは、LIST_FILE=/home/admin/list.t ...
lftpを使用して自動同期する

lftpはFTPサイトでファイルやディレクトリをダウンロードできたりアップロードできたりするコマンドです。通常のFTPクライアントではrsyncのように特定のディレクトリ ...
起動時間が一定以上のプロセスをKillするスクリプト

Cronで実行するスクリプトで実行時間が短いはずなのに長時間起動したままで終了していないプロセスがあり、プロセスが残っていた状態でメモリが使用率が増えるケースがありました。
1週間 ...
シェルスクリプトで変数内の改行を有効にする

シェルスクリプトを改行を含まれる変数をechoコマンドなどで表示した場合に、下記のように改行がスペースに変換される場合があります。
$ cat test.sh#!/bin/bashTEST="1 ...cron実行時に環境変数を読み込む

cronに登録しているスクリプトでログに特定の文字を含むとメールするスクリプトがあります。メールする本文やタイトルに日本語文字が場合に文字化けが発生しました。
スクリプト単体だと ...
サービス・プロセスの起動確認するシェルスクリプト

特定のプロセスやサービスの起動を確認して落ちていれば起動するシェルスクリプトです。
シェルスクリプトの流れは、psコマンドでプロセスを確認して、wcコマンド起 ...