File deletion when server restarts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File deletion when server restarts
# 1  
Old 11-15-2004
Power 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
# 2  
Old 11-15-2004
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 Smilie
# 3  
Old 11-16-2004
Data file deletion at Server startup

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
# 4  
Old 11-16-2004
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
# 5  
Old 11-22-2004
Hp UX

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!
# 6  
Old 11-22-2004
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
Code:
#!/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
# 7  
Old 11-22-2004
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read command restarts at beginning of file

I am reading in a file in a Korn shell script. The file has one header row followed by possibly millions of data rows. I want to do one thing to the header row and write it out to a new output file, then something different to the data rows. My code looks like this: read header < $infile ... (4 Replies)
Discussion started by: DJR
4 Replies

2. UNIX for Dummies Questions & Answers

Deletion of list of user based on a text file In LDAP UNIX server

Dear All, It would be really nice, if you could help me to write a script for deletion of list of user( more than 15000 users) stored in a file and sorted by email address( i need deletion of only a particular type of mail address). Is the any script to write and take the file as input and... (3 Replies)
Discussion started by: Chand
3 Replies

3. Shell Programming and Scripting

File content deletion

Hi Everyone, There are certain files under a folder 'ABC' and the entries for these files are there in another file(fname) under a different folder 'XYZ'. I want to compare the folder contents(ABC) with the file(fname) contents and delete the mismatching / non-existing ones from the file,... (4 Replies)
Discussion started by: swasid
4 Replies

4. Red Hat

Network always restarts

Hi guys :) I got a big problem. Yesterday I changed the IP of a server. Then i restarted the network service, did a DNS entry and so on. Nameserver are the same as always. After a few minutes after boot the network disconnects -> no ping, no ssh. Approximately 30 seconds later it starts... (1 Reply)
Discussion started by: mario_linux
1 Replies

5. Shell Programming and Scripting

want file to regenerate after deletion

I looked into the sticky bit, but I think, if possible, that I would prefer to have the file recreate itself after deletion. The file is several directories deep, and from time to time the top level directory will be trashed. I need the file to recreate after this. Is it possible to perhaps... (13 Replies)
Discussion started by: glev2005
13 Replies

6. Shell Programming and Scripting

Prompting for file deletion?

I got help in another forum but now I need further help so I figured I'd ask here. I had to write a script to delete certain filenames of certain size. I got this far.. find . -size 110c -name "*testing*" -print | xargs -n 1 rm -i It finds the correct files, but the prompts to delete are all... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. Solaris

Script for automatic deletion of trash file of mail server

Hi, I have a mail server with limited space and operating system is sun solaris 8 (sparc). I do not have provisions to increase the space for home directory. So i have to delete files from /home/username/mail/trash which are more than 10 days old automatically. So my script should be like... (1 Reply)
Discussion started by: crown2100bd
1 Replies

8. UNIX for Dummies Questions & Answers

file deletion problem

I am using unix via telnet ssh and i have a problem I was testing the server. I made a directory. Transfered a file from an ftp to it. Opened the file with the vi text editor --This where my problem came..... I tried deleting the file using rm somefile.htm when is typed ls i noticed that... (2 Replies)
Discussion started by: shdwsclan
2 Replies

9. UNIX for Dummies Questions & Answers

large file deletion

OS: Solaris 8 I deleted a large file (around 13 Gigs) from my system. But the output of df -k remains the same. The capacity % is constant. However one strange thing is happening- My available space is decreasing, my used space in increasing (The opposite should happen). This is happening... (2 Replies)
Discussion started by: run_time_error
2 Replies

10. UNIX for Dummies Questions & Answers

Deletion of File in Unix

Hi there guys. I'm quite new in using unix and just recently experienced missing file problem. Someone accidentally or likely intentionally deleted one specific folders that contains important file. Now my question is, can any other user aside from root can do such action? Please help. ... (2 Replies)
Discussion started by: rhomel101
2 Replies
Login or Register to Ask a Question