LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-27-2010, 07:46 AM   #1
2handband
Member
 
Registered: Jan 2009
Location: Alexandria, Minnesota
Distribution: KaOS
Posts: 831

Rep: Reputation: 96
Clearing /tmp


I've been using cron to clear /tmp at boot time but thought I'd try another method. After doing a little research I added the following line:

Code:
( cd /tmp && rm -rf -- * .* 2>/dev/null )
to /etc/rc.d/rc.S immediately after:

Code:
# Done checking root filesystem
And /tmp is not clearing out at boot time. This method seems to work for others; can somebody give me a hint as to what I might be doing wrong?
 
Old 12-27-2010, 08:06 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Are you sure that the root-filesystem is mounted directly after checking it?
As you know the filesystem is checked when it is still unmounted.

I think you'll have to insert your code after this:
Code:
 # Remount the root filesystem in read-write mode
  echo "Remounting root device with read-write enabled."
  /sbin/mount -w -v -n -o remount /

Markus

Last edited by markush; 12-27-2010 at 08:11 AM.
 
Old 12-27-2010, 08:32 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
You might want to consider moving your code to /etc/rc.d/rc.local -- it runs last, so everything is mounted, daemons are going and all that sort of thing (that's where I do the /tmp clean out).
 
1 members found this post helpful.
Old 12-27-2010, 09:41 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
Should be OK. Try removing 2>/dev/null so you can see any error messages.
 
1 members found this post helpful.
Old 12-27-2010, 09:55 AM   #5
niels.horn
Senior Member
 
Registered: Mar 2007
Location: Rio de Janeiro - Brazil
Distribution: Slackware64-current
Posts: 1,004

Rep: Reputation: 90
My desktop stays on for months in a row, so I run a simple script from cron.daily, deleting from /tmp all files that have not been accessed for a week.
 
Old 12-27-2010, 09:57 AM   #6
2handband
Member
 
Registered: Jan 2009
Location: Alexandria, Minnesota
Distribution: KaOS
Posts: 831

Original Poster
Rep: Reputation: 96
Put it in /etc/rc.d/rc.local and it worked. Thanks!
 
Old 12-27-2010, 10:13 AM   #7
hootee
LQ Newbie
 
Registered: Oct 2003
Location: Finland
Distribution: slackware
Posts: 10

Rep: Reputation: 2
If you clear /tmp in rc.local you remove these things that you create in rc.S

Code:
# Create /tmp/{.ICE-unix,.X11-unix} if they are not present:
if [ ! -e /tmp/.ICE-unix ]; then
  mkdir -p /tmp/.ICE-unix
  chmod 1777 /tmp/.ICE-unix
fi
if [ ! -e /tmp/.X11-unix ]; then
  mkdir -p /tmp/.X11-unix
  chmod 1777 /tmp/.X11-unix
fi
 
1 members found this post helpful.
Old 12-27-2010, 01:57 PM   #8
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 33
Quote:
Originally Posted by 2handband View Post
I've been using cron to clear /tmp at boot time but thought I'd try another method. After doing a little research I added the following line:

Code:
( cd /tmp && rm -rf -- * .* 2>/dev/null )
to /etc/rc.d/rc.S immediately after:

Code:
# Done checking root filesystem
And /tmp is not clearing out at boot time. This method seems to work for others; can somebody give me a hint as to what I might be doing wrong?
Can I just ask what is the point of the "-- * .*" section? I've not seen that string before.

If I (with my limited bash knowledge) wanted to do that i'd just use "./*"

I assume yours is better but why, what does it do? Thanks
 
Old 12-27-2010, 02:00 PM   #9
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
The double dash indicates rm that the rest of the arguments are positional and not options, should you have a file named "-i", for example. The first asterisk expands to the list of files and directories excluding the ones that are hidden. That's, I think, the point of the third dot-asterisk argument. However, that dangerously expands to include ".." too, so I'm not sure if I'd use it.
 
Old 12-27-2010, 02:06 PM   #10
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 33
Quote:
Originally Posted by rg3 View Post
However, that dangerously expands to include ".." too, so I'm not sure if I'd use it.
Thanks. You concern above has been raised in another thread on this topic, but apparently rm is designed to not remove . or .. so it should be safe.


EDIT - following hootee's post above, would it be an idea to avoid rmoving hidden files? ie

Code:
( cd /tmp && rm -rf -- * 2>/dev/null )

Last edited by spoovy; 12-27-2010 at 02:10 PM.
 
Old 12-27-2010, 02:24 PM   #11
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
Oh, yeah, I should have noted that the way I do this (from /etc/rc.local is with the find utility:
Code:
find /tmp -mtime +1 -print -exec rm -r {} \;
  • The -print is not necessary (it prints the list of stuff it's going to blow away, the list winds up in a log);
  • the -mtime +1 only finds stuff older than 1 day (so you don't blow away anything created during start up).
  • /tmp doesn't get blown away because it was modified a few seconds ago by start up stuff.
  • You can bury this is a shell program if you want (keeping the "standard Slackware way" intact; i.e., the check for an existing, executable file named rc.blah (which are, those rc.blah file, after all else is said, just shell programs)).
Hope this helps some.
 
Old 12-27-2010, 02:49 PM   #12
hootee
LQ Newbie
 
Registered: Oct 2003
Location: Finland
Distribution: slackware
Posts: 10

Rep: Reputation: 2
Quote:
Originally Posted by tronayne View Post
[*]the -mtime +1 only finds stuff older than 1 day (so you don't blow away anything created during start up).
But those directories in rc.S will be created only when they are missing. And if they are not created now they will be possibly removed.
 
Old 12-27-2010, 03:01 PM   #13
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 33
I think because they have just been created they will have timestamps < 1 day therefore be left alone.

Also, not being pedantic but just found this re "find -mtime" - http://www.unix.com/unix-dummies-que...f-one-day.html

So it looks like "-mtime +0" would find stuff older than 1 day, not "-mtime +1".

Last edited by spoovy; 12-27-2010 at 03:03 PM.
 
Old 12-27-2010, 03:07 PM   #14
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
Quote:
Originally Posted by spoovy View Post
I think because they have just been created they will have timestamps < 1 day therefore be left alone.

Also, not being pedantic but just found this re "find -mtime" - http://www.unix.com/unix-dummies-que...f-one-day.html

So it looks like "-mtime +0" would find stuff older than 1 day, not "-mtime +1".
Maybe in 2005 (not that I can remember, though)...

-mtime +1 returns anything more than 24 hours old.

If you want "today," just use -mtime -1.

Last edited by tronayne; 12-27-2010 at 03:09 PM.
 
Old 12-27-2010, 03:38 PM   #15
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 33
Yeah you're right. I'm not sure the man page makes sense in that respect.

Shouldn't it be -atime rather than -mtime though? As the hidden files won't be modified by rc.local therefore won't be spared when your code cleans /tmp. But they will presumably be "accessed" by the rc.local script when it checks if they are present or not.

Or am I misunderstanding ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Clearing /tmp at shutdown 2handband Slackware 8 11-09-2010 04:14 PM
TRAC - something is clearing /tmp Lantzvillian Linux - Software 1 03-06-2010 08:49 AM
Can't login, says tmp directory full but tmp file is empty! Could be linked to MySQL? bethanlowder Fedora 7 09-25-2009 07:17 AM
how to securing /tmp , /var/tmp and /dev/shm hackintosh Linux - Security 7 10-17-2007 11:26 PM
[SOLVED] clearing /tmp at reboot sylye Debian 2 08-26-2006 04:42 AM

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

All times are GMT -5. The time now is 04:05 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration