How can I delete few files from a directory at restart of my OS before getting logged ? I am using ubuntu 19.10?

How can I delete few files from a directory at restart of my OS before getting logged ? I am using ubuntu 19.10?

I created a file rc.local in etc folder and one process start by using this file which works smoothly. I just Additional add one line to remove few files from dir my code as follows

#!/bin/sh -e
ads start
exit 0

This works well and each time system restart my process starts. Now I add a line after my process like this

#!/bin/sh -e
ads start
rm /dataTemp/*.tmp
exit 0

This works for a single restart , if I restart the system again rc.local never loads.

I use

sudo service rc.local start 

to start the service when it fails each time.

Please help me to solve this issue

答案1

You could try using a Cronjob that will run on boot. from your terminal type

crontab -e

Then add the @reboot to your rm /dataTemp/*.tmp command to your cronjob list for example @reboot rm /dataTemp/*.tmp .

相关内容