LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-28-2007, 07:45 AM   #1
adityavpratap
Member
 
Registered: Dec 2004
Location: Hyderabad, India
Distribution: Slackware 13, Ubuntu 12.04
Posts: 440

Rep: Reputation: 32
automatically emptying /tmp at shutdown


Hi!
I want to empty /tmp folder on shutdown. I think -
Code:
rm -rf /tmp/*
should do the trick provided it is given in the appropriate script. Can I give it in /etc/rc.d/rc.6?
 
Old 01-28-2007, 08:05 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well i'm not familiar with slackware really, but i'd suggest a more elegnat solution like using a tmpfs filesystem as /tmp. this will hold all data in memory / swap partition and so won't persist across a boot anyway. just a line in your fstab file like

tmpfs /tmp tmpfs defaults 0 0

in actual fact though, you may well already have a similar line to /dev/shm or such like, ready to do the same job... could just use a symlink to it if you have one (redhat based systems do...)

if you do wish to just delete files, i'd recommend clearing it on startup, not shutdown though, just as simple but with less chance of busting a runlevel.
 
Old 01-28-2007, 08:47 AM   #3
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
I do mine at startup with a line in a rc.custom file that runs from rc.local.

rm -r /tmp/* 2&>/dev/null
 
Old 01-28-2007, 09:20 AM   #4
erklaerbaer
Member
 
Registered: Mar 2006
Posts: 381

Rep: Reputation: 30
since version 11 you can write a rc.local_shutdown file.
Quote:
#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
#
# Put any local startup commands in here. Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.
regards,
 
Old 01-28-2007, 11:18 AM   #5
adityavpratap
Member
 
Registered: Dec 2004
Location: Hyderabad, India
Distribution: Slackware 13, Ubuntu 12.04
Posts: 440

Original Poster
Rep: Reputation: 32
Thank you all for your suggestions. My problem is sorted out.
 
Old 01-28-2007, 11:51 AM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
The only question is when can the /tmp directory be safely deleted ? At bootup or shutdown ? I wouldn't know.
 
Old 01-28-2007, 01:55 PM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Either one is just as safe.
 
Old 01-28-2007, 02:40 PM   #8
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Rep: Reputation: 63
I added this to my rc.6, after the section that clears /var/log/subsys, when using 10.1 and have never had any issues then, in 10.2 or 11.

#Clean temporary directories
/bin/echo "Cleaning temp files."
/usr/bin/rm -R /tmp/* ; /usr/bin/rm -R /var/tmp/*
 
Old 01-28-2007, 04:52 PM   #9
MQMan
Member
 
Registered: Jan 2004
Location: Los Angeles
Distribution: Slack64 14.1
Posts: 581

Rep: Reputation: 38
DON'T clear everthing in /tmp from a script in /etc/rc.d/rc.local. You might trash the hidden directories required by X that are checked for, and created in /etc/rc.d/rc.S.

Cheers.
 
Old 01-29-2007, 12:08 AM   #10
adityavpratap
Member
 
Registered: Dec 2004
Location: Hyderabad, India
Distribution: Slackware 13, Ubuntu 12.04
Posts: 440

Original Poster
Rep: Reputation: 32
MQMan is right. The best place to put the housekeeping script is either /etc/rc.d/rc.local_shutdown as erklaerbaer has pointed out or in during the startup or better still to mount tmpfs on /tmp as pointed out by acid_kewpie.
 
Old 01-31-2007, 07:46 AM   #11
ferradura
Member
 
Registered: Jun 2006
Location: PT
Distribution: CRUX & Slackware
Posts: 100

Rep: Reputation: 15
Quote:
Originally Posted by adityavpratap
to mount tmpfs on /tmp as pointed out by acid_kewpie.
i would like to have some info on this...what to change in fstab?
 
Old 01-31-2007, 08:55 AM   #12
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
http://wiki.linuxquestions.org/wiki/Tmpfs
 
Old 01-31-2007, 09:12 AM   #13
ferradura
Member
 
Registered: Jun 2006
Location: PT
Distribution: CRUX & Slackware
Posts: 100

Rep: Reputation: 15
Quote:
Originally Posted by tuxdev
thank you
 
Old 01-31-2007, 09:25 AM   #14
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
I use tmpfs but there's also something called bootclean
/etc/init.d/bootclean
that removes old files but not some exceptions.
I post it here because I'm not sure all distro have it:

mkflagfile()
{
# Prevent symlink attack (See #264234.)
[ -L "$1" ] && log_warning_msg "bootclean: Deleting symbolic link '$1'."
rm -f "$1" || { log_failure_msg "bootclean: Failure deleting '$1'." ; return 1 ; }
# No user processes should be running, so no one should be able to introduce
# a symlink here. As an extra precaution, set noclobber.
set -o noclobber
:> "$1" || { log_failure_msg "bootclean: Failure creating '$1'." ; return 1 ; }
return 0
}


clean_tmp() {
cd /tmp || { log_failure_msg "bootclean: Could not cd to /tmp." ; return 1 ; }

#
# Only clean out /tmp if it is world-writable. This ensures
# it really is a/the temp directory we're cleaning.
#
[ "$(find . -maxdepth 0 -perm -002)" = "." ] || return 0

if [ ! "$TMPTIME" ]
then
log_warning_msg "Using default TMPTIME 0."
TMPTIME=0
fi

[ "$VERBOSE" = no ] || log_action_begin_msg "Cleaning /tmp"

#
# Remove regardless of TMPTIME setting
#
rm -f .X*-lock

#
# Don't clean remaining files if TMPTIME is negative or 'infinite'
#
case "$TMPTIME" in
-*|infinite|infinity)
[ "$VERBOSE" = no ] || log_action_end_msg 0 "skipped"
return 0
;;
esac

# Wipe /tmp, excluding system files, but including lost+found
#
# If TMPTIME is set to 0, we do not use any ctime expression
# at all, so we can also delete files with timestamps
# in the future!
#
if [ "$TMPTIME" = 0 ]
then
TEXPR=""
DEXPR=""
else
TEXPR="-mtime +$TMPTIME -ctime +$TMPTIME -atime +$TMPTIME"
DEXPR="-mtime +$TMPTIME -ctime +$TMPTIME"
fi

EXCEPT='! -name .
! ( -path ./lost+found -uid 0 )
! ( -path ./quota.user -uid 0 )
! ( -path ./aquota.user -uid 0 )
! ( -path ./quota.group -uid 0 )
! ( -path ./aquota.group -uid 0 )
! ( -path ./.journal -uid 0 )
! ( -path ./.clean -uid 0 )
! ( -path './...security*' -uid 0 )'

mkflagfile /tmp/.clean || return 1

report_err()
{
if [ "$VERBOSE" = no ]
then
log_failure_msg "bootclean: Failure cleaning /tmp."
else
log_action_end_msg 1 "bootclean: Failure cleaning /tmp"
fi
}

#
# First remove all old files...
# (Use xargs here so that only one additional process gets created)
#
find . -depth -xdev $TEXPR $EXCEPT ! -type d \
-print0 | xargs -0r rm -f -- \
|| { report_err ; return 1 ; }

#
# ...and then all empty directories
# (Don't use xargs here because dirs must be removed one by one from
# the bottom up)
#
find . -depth -xdev $DEXPR $EXCEPT -type d -empty \
-exec rmdir \{\} \; \
|| { report_err ; return 1 ; }

[ "$VERBOSE" = no ] || log_action_end_msg 0
return 0
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically shutdown jsteegh Slackware 3 09-09-2006 11:45 AM
Automatically running script at shutdown samac Slackware 2 05-14-2005 10:10 AM
Why was the relocated /tmp write permission automatically reset (lost)? wirawan0 Mandriva 2 06-26-2004 07:33 PM
slack doesnt shutdown automatically?? yenonn Slackware 6 01-02-2004 09:38 AM
/tmp wiped automatically? rob19 Linux - General 4 12-14-2003 09:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration