Based on some posts here, I try to run a simple script to clean up a folder with temporary content on restart and shutdown.
Following the instructions and the READMEs I wrote this script:
/etc/init.d/cleantmp
#!/bin/sh
### BEGIN INIT INFO
# Provides: cleantmp
# Required-Start:
# Required-Stop: $local_fs
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: clean temporary folders
# Description:
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
echo "Clean up temporary folders"
rm -rf /home/user/tmp/*
Then I gave it the execution rights:
$ sudo chmod +x /etc/init.d/cleantmp
$ ls -l /etc/init.d/cleantmp
-rwxr-xr-x 1 root root 329 Dec 19 12:50 /etc/init.d/cleantmp
Then I update the rc:
$ sudo update-rc.d cleantmp defaults
$ ls -l /etc/rc?.d/*cleantmp
lrwxrwxrwx 1 root root 18 Dec 19 13:12 /etc/rc0.d/K01cleantmp -> ../init.d/cleantmp
lrwxrwxrwx 1 root root 18 Dec 19 13:12 /etc/rc1.d/K01cleantmp -> ../init.d/cleantmp
lrwxrwxrwx 1 root root 18 Dec 19 13:12 /etc/rc6.d/K01cleantmp -> ../init.d/cleantmp
So far so good. But after shutdown and start or a reboot, the temporary files still exist. If I directly call one of the symlinks using sudo
the files correctly disappear.
What is wrong here?
OS: Linux 4.4.0-104-generic #127-Ubuntu | Ubuntu Gnome 16.04.3 LTS 64-bit