LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-12-2005, 06:51 PM   #1
AVD_ZM
Member
 
Registered: Oct 2004
Location: HELLAS aka Greece
Distribution: K/Ubuntu Knoppel
Posts: 114

Rep: Reputation: 15
how do you clear tmp?


was wondering how do i clear the tmp folder?

without actaully deleting all the files i n it.

thanx
 
Old 02-12-2005, 08:22 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Mineral, Virginia
Distribution: Debian 8
Posts: 7,891

Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339
"was wondering how do i clear the tmp folder?

without actaully deleting all the files i n it."

I am not sure what you mean by clearing /tmp without deleting files. The way that I clean /tmp is to delete all of the files in /tmp during shutdown. That way I don't crash a running program by deleting an active file in /tmp. I place these commands:
echo "cleaning /tmp"
rm /tmp/* -R
in /etc/init.d/halt.local. I use SuSE 9.1. I don't know what the equivalent files are in Mandrake or FC3.

-------------------------
Steve Stites
 
Old 02-13-2005, 07:19 PM   #3
AVD_ZM
Member
 
Registered: Oct 2004
Location: HELLAS aka Greece
Distribution: K/Ubuntu Knoppel
Posts: 114

Original Poster
Rep: Reputation: 15
here's my /etc/init.d/halt file
now where should i put it??
Code:
#!/bin/bash 
# 
# halt          This file is executed by init when it goes into runlevel 
#               0 (halt) or runlevel 6 (reboot). It kills all processes, 
#               unmounts file systems and then either halts or reboots. 
# 
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> 
#               Modified for RHS Linux by Damien Neil 
# 
 
NOLOCALE=1 
. /etc/init.d/functions 
 
runcmd() { 
   echo -n "$1 " 
   shift 
   if [ "$BOOTUP" = "color" ]; then 
      $* && echo_success || echo_failure 
   else 
      $* 
   fi 
   echo 
} 
 
halt_get_remaining() { 
	awk '$2 ~ /^\/$|^\/proc|^\/sys|^\/dev/{next} 
	     $3 == "tmpfs" || $3 == "proc" {print $2 ; next} 
	     /(^#|loopfs|autofs|devfs|^none|^\/dev\/ram|^\/dev\/root)/ {next} 
	     {print $2}' /proc/mounts 
} 
 
# See how we were called. 
case "$0" in 
   *halt) 
	message=$"Halting system..." 
	command="/sbin/halt" 
	;; 
   *reboot) 
	message=$"Please stand by while rebooting the system..." 
	command="/sbin/reboot" 
	;; 
   *) 
	echo $"$0: call me as 'halt' or 'reboot' please!" 
	exit 1 
	;; 
esac 
case "$1" in 
   *start) 
   	;; 
   *) 
	echo $"Usage: $0 {start}" 
	exit 1 
	;; 
esac 
 
# Kill all processes. 
[ "${BASH+bash}" = bash ] && enable kill 
 
runcmd $"Sending all processes the TERM signal..." /sbin/killall5 -15 
sleep 5 
runcmd $"Sending all processes the KILL signal..."  /sbin/killall5 -9 
 
# Write to wtmp file before unmounting /var 
/sbin/halt -w 
 
# Save mixer settings, here for lack of a better place. 
grep -q "\(alsa\)" /proc/devices 
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then 
   runcmd $"Saving mixer settings" alsactl store 
fi 
 
# Save random seed 
touch /var/lib/random-seed 
chmod 600 /var/lib/random-seed 
runcmd $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null 
 
# Sync the system clock. 
ARC=0 
SRM=0 
UTC=0 
 
if [ -f /etc/sysconfig/clock ]; then 
   . /etc/sysconfig/clock 
 
   # convert old style clock config to new values 
   if [ "${CLOCKMODE}" = "GMT" ]; then 
      UTC=true 
   elif [ "${CLOCKMODE}" = "ARC" ]; then 
      ARC=true 
   fi 
fi 
 
CLOCKDEF="" 
CLOCKFLAGS="$CLOCKFLAGS --systohc" 
 
case "$UTC" in 
   yes|true) 
	CLOCKFLAGS="$CLOCKFLAGS -u"; 
	CLOCKDEF="$CLOCKDEF (utc)"; 
	;; 
   no|false) 
	CLOCKFLAGS="$CLOCKFLAGS --localtime"; 
	CLOCKDEF="$CLOCKDEF (localtime)"; 
	;; 
esac 
 
case "$ARC" in 
   yes|true) 
	CLOCKFLAGS="$CLOCKFLAGS -A"; 
	CLOCKDEF="$CLOCKDEF (arc)"; 
	;; 
esac 
case "$SRM" in 
   yes|true) 
	CLOCKFLAGS="$CLOCKFLAGS -S"; 
	CLOCKDEF="$CLOCKDEF (srm)"; 
	;; 
esac 
 
runcmd $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS 
 
# Turn off swap, then unmount file systems. 
[ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps` 
[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS 
 
[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug 
 
# Unmount file systems, killing processes if we have to. 
# Unmount loopback stuff first 
remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts` 
devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts` 
[ -n "$remaining" ] && { 
	sig= 
	retry=3 
	while [ -n "$remaining" -a "$retry" -gt 0 ] 
	do 
		if [ "$retry" -lt 3 ]; then 
			runcmd $"Unmounting loopback filesystems (retry):" umount $remaining 
		else 
			runcmd $"Unmounting loopback filesystems: " umount $remaining 
		fi 
		for dev in $devremaining ; do 
			losetup $dev > /dev/null 2>&1 && \ 
				runcmd $"Detaching loopback device $dev: " losetup -d $dev 
		done 
		remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts` 
		devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts` 
		[ -z "$remaining" ] && break 
		/sbin/fuser -k -m $sig $remaining >/dev/null 
		sleep 5 
		retry=$(($retry -1)) 
		sig=-9 
	done 
} 
 
# Unmount RPC pipe file systems 
sig= 
retry=3 
remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts` 
 
while [ -n "$remaining" -a "$retry" -gt 0 ] 
do 
	if [ "$retry" -lt 3 ]; then 
		runcmd $"Unmounting pipe file systems (retry): "  umount -f $remaining 
	else 
		runcmd $"Unmounting pipe file systems: "  umount -f $remaining 
	fi 
	sleep 2 
	remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts` 
	[ -z "$remaining" ] && break 
	/sbin/fuser -k -m $sig $remaining >/dev/null 
	sleep 5 
	retry=$(($retry-1)) 
	sig=-9 
done 
 
sig= 
retry=3 
remaining=`halt_get_remaining | sort -r` 
 
while [ -n "$remaining" -a "$retry" -gt 0 ] 
do 
	if [ "$retry" -lt 3 ]; then 
		LANG=C runcmd $"Unmounting file systems (retry): "  umount -f $remaining 
	else 
		LANG=C runcmd $"Unmounting file systems: "  umount -f $remaining 
	fi 
	sleep 2 
	remaining=`halt_get_remaining | sort -r` 
	[ -z "$remaining" ] && break 
	/sbin/fuser -k -m $sig $remaining >/dev/null 
	sleep 5 
	retry=$(($retry-1)) 
	sig=-9 
done 
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb 
 
# remove the crash indicator flag 
rm -f /.autofsck 
 
# Try all file systems other than root and RAM disks, one last time. 
mount |  awk '!/( \/ |^\/dev\/root|^\/dev\/ram| \/proc )/ { print $3 }' | \ 
  while read line; do 
    umount -f $line 
done 
 
# Remount read only anything that's left mounted. 
# echo $"Remounting remaining filesystems readonly" 
mount | awk '{ print $3 }' | while read line; do 
    mount -n -o ro,remount $line 
done 
 
# Now halt or reboot. 
echo $"$message" 
if [ -f /fastboot ]; then 
 echo $"On the next boot fsck will be skipped." 
elif [ -f /forcefsck ]; then 
 echo $"On the next boot fsck will be forced." 
fi 
 
if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then 
	. /etc/sysconfig/ups 
	if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then 
		/sbin/upsdrvctl shutdown 
	elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then 
		$MODEL $OPTIONS_HALT -k $DEVICE 
	fi 
fi 
 
if [ -x /sbin/halt.local ]; then 
   /sbin/halt.local 
fi 
 
HALTARGS="-i -d" 
[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p" 
 
exec $command $HALTARGS
 
Old 02-13-2005, 07:58 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Mineral, Virginia
Distribution: Debian 8
Posts: 7,891

Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339
"here's my /etc/init.d/halt file
now where should i put it??"

I would first try it between the following two lines.

[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug

# Unmount file systems, killing processes if we have to.



[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug

# The following commands were added by AVD_ZM to clean /tmp
echo "cleaning /tmp"
rm /tmp/* -R

# Unmount file systems, killing processes if we have to.



----------------------------------
Steve Stites
 
Old 02-14-2005, 05:54 AM   #5
AVD_ZM
Member
 
Registered: Oct 2004
Location: HELLAS aka Greece
Distribution: K/Ubuntu Knoppel
Posts: 114

Original Poster
Rep: Reputation: 15
Thanx man, it works!!!! :-)
 
  


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
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 05:02 PM
kde, /tmp, /var/tmp and all that garba Linux - Software 4 06-17-2005 12:31 PM
/tmp fills up and doesn't clear itself cz1179 Linux - General 1 01-10-2005 03:50 AM
Numerous scb_*.tmp files in /tmp dburk Programming 3 08-18-2003 04:28 PM
Newbie question - /tmp /var/tmp Mr happy Linux - Security 3 01-27-2003 01:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:06 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