フォアグラウンドプロセスでルートシェルを使用してbashスクリプトを終了する方法

フォアグラウンドプロセスでルートシェルを使用してbashスクリプトを終了する方法

メモリをクリーンアップするクリーンアップスクリプトcleanup.shがあります。

スクリプト:

# root script starts here
echo ".........running clean up script ..........."

/usr/local/packages/aime/ias/run_as_root "su -"
free -t
sync; echo 1 > sudo /proc/sys/vm/drop_caches
free -t
sync; echo 2 > sudo  /proc/sys/vm/drop_caches
free -t
sync; echo 3 > sudo /proc/sys/vm/drop_caches
free -t
swapoff -a && swapon -a
echo "#####swapoff and swap on command ############"
free -g
exit
# root script ends here
free -g

スクリプトの終わり

スクリプトはルートを使用してこれらの操作を実行しますが、ルートプロンプトを終了することはできません。

0番出口、1番出口、{exit}すべて試しました。

プロセスが前面に出ています。このスクリプトを起動するシェルにどのように移動しますか?

スクリプトを実行し、root でスクリプトを実行します。

[sgongali@slc06wvd cronjob]$ ./cleanup.sh
.........running clean up script ...........
[root@slc06wvd ~]# 

手動で終了すると、次の結果が表示されます。 swapoff -a && swapon -a はスクリプトの一部としては機能しませんが、手動で動作します。

[root@slc06wvd ~]# exit
logout
             total       used       free     shared    buffers     cached
Mem:      15037256   12776036    2261220     793448     382132    3357904
-/+ buffers/cache:    9036000    6001256
Swap:     15826924          0   15826924
Total:    30864180   12776036   18088144
             total       used       free     shared    buffers     cached
Mem:      15037256   12776036    2261220     793448     382140    3357896
-/+ buffers/cache:    9036000    6001256
Swap:     15826924          0   15826924
Total:    30864180   12776036   18088144
             total       used       free     shared    buffers     cached
Mem:      15037256   12776036    2261220     793448     382160    3357876
-/+ buffers/cache:    9036000    6001256
Swap:     15826924          0   15826924
Total:    30864180   12776036   18088144
             total       used       free     shared    buffers     cached
Mem:      15037256   12776104    2261152     793448     382164    3357872
-/+ buffers/cache:    9036068    6001188
Swap:     15826924          0   15826924
Total:    30864180   12776104   18088076
./cleanup.sh: line 14: swapoff: command not found
#####swapoff and swap on command ############
             total       used       free     shared    buffers     cached
Mem:            14         12          2          0          0          3
-/+ buffers/cache:          8          5
Swap:           15          0         15
[sgongali@slc06wvd cronjob]$ 

ベストアンサー1

which swapoffとを実行しwhich swapon、スクリプトのフルパスを使用します。または、PATHスクリプトの先頭でenvを更新し、そのバイナリを含むディレクトリを追加します。

おすすめ記事