シェルスクリプトでコマンドの結果を変数に代入する

シェルスクリプトで、コマンドの実行結果を変数に代入したいケースがあります。代入する方法は下記のようなコマンド代入できます。
結果を代入したいコマンドをバッククォート(`)で囲むか、$()の括弧の部分にコマンドをいれるかのどちら ...
SQL文をコマンドで実行した場合に結果のみの値を取得する

MySQL(MariaDB)で、SQL分をコマンドで実行するとカラムが表示されます。SQL分を叩く箇所をシェルスクリプト内で使いたいのでカラム無 ...
swapが使用しているプロセスのTOP10を表示する

最近、サーバーのメモリが逼迫してswapを使っている場合があり、どのプロセスが使用しているか確認したいのでその方法を調べました
/proc 以下のプロセス情報で確認する使用しているプ ...
psコマンドで、CPU使用率・メモリ使用量でソートする

PSコマンドでは、通常ではプロセスID順に並んでいますが、この並びをCPU使用率・メモリの使用率に変更して表示する事ができます。CPUやメモリ以外の項目でもソートできるので詳し ...
ディレクトリごとの容量が大きい順で並び替えて表示する

ディスク容量が少なくなって、どのディレクトリが使用しているか確認したいときに「du」コマンドで使用している容量は下記のように確認できます
$ sudo du -sh/var/www/vhosts/*/219M/var/www/v ...シェルスクリプトでwhile文で使用した変数がループ外で反映されない場合

下記のようなシェルスクリプトでwhileループ内読み込んだファイルの内容を表示して、行数をカウントしています。
while内では、変数が表示されますがwhileループの外だと変数は「0」と表示されます
「acme.sh」でルートの鍵長を指定する【無料SSL証明書】

古いサーバーで、pythonのバージョンが古いので「acme.sh」を利用して無料のSSL証明書を発行しました
証明書のチェックをCMANのSSLチェックでおこなうと、ルートの鍵長が「256」となっていました。OPENSSLで ...
URLをシェルスクリプトで監視する

先日、「.htaccess」を編集して記述ミスがあったらしくしばらく「Internal Server Error 500」でHPが停止していました。プロセス監視はしていますがURLのチェックをしていないので下記のシェルスクリプトで監視 ...
WordPress の管理画面にIPアドレス制限 【Apache 2.4系】

WordPress の不正アクセスで多いのは管理画面でログインできる「wp-login.php」にアクセスが多いです。ログで確認すると海外からアクセスが多いので、WAF(Web Application Firewall)のModSec ...
メンテナンスモードで「fstab」の書き込みができなくなった場合の対処方法

LinuxサーバーでHD故障でディスクを外してたりして再起動しました。故障したHDの「fstab」の故障したHDのマウントしている箇所のコメントアウトを忘れていたので、起動時に失敗しました。
画面ではメンテナンスモードに移 ...
ModSecurityでホワイトリスト・ブラックリストを追加

無料のWAFの「ModSecurity」でホワイトリストとブラックリストを設定する方法を説明します。「ModSecurity」のインストール方法は「無料のWAF(Web Application Firewall)のModSecurit ...
一時的にManページを日本語で表示する

以前の記事で「CentOS manコマンドを日本語表示にする」で、manページを日本語に変更する方法を紹介していました。
以前の方法では環境自体が日本語環境になるので、普段は英語環境のほうが良いってユーザーもいるかと思います。 ...
dovecotの設定内容の確認(doveconf)

メールサーバーの設定を見直していて、Dovecot側設定一覧を確認したくて、postfix の「postconf」のようなコマンドがないか探していたら「doveconf」のコマンドがありました
$ doveconf# 2.2.3 ...シェルスクリプトで特定の文字がある場合の分岐

シェルスクリプトの「if」文で特定の文字が含まれる場合の分岐は、 ] のように検索したい文字を*で囲みます。「*」は任意の文字列を表すワイルドカードとして使用されています
以下のシェルスクリプトでは、変数内(VARNAME ...
SSL証明書のチェックで脆弱性のまたは強度の弱い暗号スイートを使用している可能性の警告

CentOS 6で運用しているサーバーでSSL証明書を更新して、CMANの「SSLチェック【証明書・プロトコル・暗号スイート確認】」でSSL証明書をチェックすると下記のように「脆弱性または強度が弱い暗号化スイートを使用している可能性が ...