我有一个清理内存的清理脚本 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
脚本结束
该脚本使用 root 并执行这些操作,但无法退出 root 提示符
我尝试了 exit 0、exit 1 和 {exit} 全部
该进程正在进入前台,如何 gabck 到我启动此脚本的 shell
运行脚本并以 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,并将包含这些二进制文件的目录添加到其中。