File deletion when server restarts

Hi,

In a shell script I am makin use of 3 files f1,f2 and f3.txt.
When the Unix server is restarted I want to delete all these 3
files if they are existing.

( I suppose I will have to use this command
rm /thefilepath/f*
but dont know in which script to use.)

Anyone knows what can be done for this.

Thanks

If you are not too particular that the files should be deleted only after the server is restared, you can put the remove statement in your .profile (unix) or .bash_profile(linux). This will remove the files whenever you start a shell.

Otherwise this is not at all an acceptable solution :slight_smile:

Thanks sarmakdvsr for your reply.

But I wanted the files to be deleted during the Unix server start up only.

Can anyone help me for this.

Thanks

Which *nix are you using?

If you're using Linux (or other System V based *nixes), for example, you can create a script under /etc/rc.d (or /etc/init.d - use the existing scripts as templates), and then create an SXXfoo symlink in the appropriate runlevel directory (/etc/rcX.d) to have the files be automatically deleted at system startup.

Cheers
ZB

I am using HP -UX .

Under /etc/ I have 'rc.config.d' folder which shows many files/scripts.

Do I have to create a script under this folder 'rc.config.d'?
Can I give any name to the script like 'scleanfs'.

scleanfs
------------------
#!/usr/bin/sh
rm /complete_dirpath/f*
------------------

Will this work?

------------------------------------------------------------------
Is it that whenever a unix server restarts, all the scripts present
in a particular folder under /etc/ get executed???
( And in case of HP-UX this folder is rc.config.d ??? )
------------------------------------------------------------------

Thanks!

The scripts will be found under /sbin/init.d

Try reading this (the HP-UX stuff is in the second half of the document).

Create a script something along the lines of

#!/usr/bin/sh
case "$1" in
start) rm /complete_dirpath/f*
       ;;
esac

Name it /sbin/init.d/scleanfs and make it executable.

Then, create a soft link under /sbin/rc3.d (or whatever runlevel directory is required) called S999scleanfs (numbers are sequence numbers - change as necessary) pointing at /sbin/init.d/scleanfs, change to runlevel 3 (or whatever runlevel you use - or reboot) and the thing should run.

Cheers
ZB

Another option may be to put the files in /tmp - most servers I've worked on have a script that removes everything in /tmp on reboot - you would have to check to see if your server is set up this way or not.