0

I have a clean up script which cleans up memory cleanup.sh

Script :

# 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

script end

The script uses root and doing the stuff but could not able come out of root prompt

i tried exit 0, exit 1 and {exit} all

the process is comming to foreground , how to gabck to the shell where i started this script

running the script and script staying just as root

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

after i give exit manually what i get is below Note that swapoff -a && swapon -a is not working as part of script but its working manually

[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]$ 
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Suman g
  • 109
  • 3
  • Related: https://askubuntu.com/questions/638387/logout-current-user-from-script That might already be a solution for you. – Panki Nov 27 '18 at 08:22
  • I do not recommend abusing of drop_caches 3, maybe 2, and that swapoff. If you need to (ab)use it regularly in a particular VM, maybe it is time to add more RAM. – Rui F Ribeiro Nov 27 '18 at 08:36
  • 2
    Related: [Running a part of shell script as a different user](https://unix.stackexchange.com/questions/274650/running-a-part-of-shell-script-as-a-different-user) – Mark Plotnick Nov 27 '18 at 08:43

1 Answers1

0

Run which swapoff and which swapon, and use full path in your script. Or update PATH env at the begining of the script, and add directory contains those binaries into it.

Alexander
  • 1,366
  • 1
  • 7
  • 14