ChatGPTでプロセスを監視するシェルスクリプトを作成

最近、話題になっている「ChatGPT」を利用して簡単なシェルスクリプトを作成してみました。
「ChatGPT」は、OpenAIが開発した対話型AIチャットボットです。対話型で質問をすればAIが回答してくれます。
...
シェルスクリプトで引数でループする処理する方法(for文)

シェルスクリプトで全ての引数だけfor文でループ処理するには、下記のようなコードになります
#!/bin/bashfor i in "${@}"; do echo $idonefor文の構文は以下のようになります
f .../bin/bash^M: bad interpreter: No such file or directory の時の対処法

いつもは、LinuxにSSHログインしてvim コマンドでシェルスクリプトを作るのですが、Windowsでテキストエディタでシェルスクリプトで作ると改行コードが「\r\n」で保存されて、シェルスクリプトを実行すると下記のようなエラーに ...
sshd が起動しない(sshd: no hostkeys available — exiting.)

サーバーの管理は、Cockpitで管理していてサービスのメニューを確認すると「cloud-init」が起動に失敗していたので、手動で起動するとSSHのパスワード認証でログインできなくなった。
複数のサーバーも作らないので「 ...
nohupで実行した出力結果を、nohup.out以外のファイルに保存する

nohupを実行すると、コマンド実行時の標準出力・標準エラーは「nohup.out」のファイルに追加されます。
ファイルが肥大したり、以前の ...
SSHログインでログイン失敗を確認する方法

CentOSでは、SSHログイン・コンソール操作に関するログは「/var/log/secure」に保存されています
Debian, Ubuntuでは、SSHログイン・コンソール操作に関するログは「/var/log/auth ...
ディレクトリ内のファイルをzipで圧縮する

ディレクトリ内のファイルをzipファイルに圧縮するには「zip」コマンドを圧縮できます
書式は「zip -r 」になります。「-r」でサブディレクトリを含めて圧縮できます
zip -r example_com.zi ...javaのバージョンを確認する方法

LinuxでJavaのバージョンを確認するには「java -version」のコマンドで確認できます。但し、Javaがインストールされている場合です
$ java -versionopenjdk version "11.0.17 ...サーバーをシャットダウン時に「A stop job is running for …」と表示されサーバーが停止しない

Zabbixを運用しているクラウドのサーバーで、仮想マシンを停止時に「A stop job is running for Zabbix Server」と表示され永遠と停止されなくなります。停止できなくなるので「強制的に停止する」のオプ ...
userdel でユーザー削除時にホームディレクトリも削除する

Linuxでユーザーを削除するときは、「userdel」のコマンドを削除しますがこのコマンドで何もオプションを使用しない場合は、ホームディレクトリやメールスプールのディレクトリが残ってしまいます
# testユーザーを作成します ...シェルスクリプトで「integer expression expected」のエラー

昔作ったシェルスクリプトで久しぶりに実行してみたら、下記のように「integer expression expected」とエラーが上がって処理ができていませんでした
sh test.sh: line 6: ; then ec ...自動起動しているサービスの確認

CentOS 6では自動起動を設定しているサービスの確認は、下記のように「chkconfig」でおこなえました
# CentOS 6$ chkconfig --list ...MariaDBで「ERROR 1040 (08004): Too many connections」のエラー

WEBサーバーが重くてアクセスできにくいと申告があったので、下記のようにWordpressのDBにログインしようと思ったら「ERROR 1040 (08004): ...
Let’s encrypt で別サーバーで稼働している証明書を取得

今回サーバー移設の話がありました。レンサバで運用していて別のクラウドに移設するとの事です。WebコンテンツやDBは移設側にコピーできたのですが、レンタルサ ...
実行中のコマンドをバックグランドで実行する

100G以上ある大きなデータベースをエクスポートしたら数時間かかりそうで、実行中のコマンドをバックグランドに回したくなりました。コマンド実行時に「nohup」を使えばいいですが忘れていました
実行途中でバックグランドで実行 ...