Advertisement
FlyFar

m_stale.sh

May 16th, 2024
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.81 KB | Cybersecurity | 0 0
  1. #!/bin/sh
  2. ##
  3. ## 8-1-97 Ian Kinner (ian@llc.net)
  4. ##
  5. ## Simple sh script to remove stale files left in the in.pop3d tmp
  6. ## directory, which cause DoS for POP3 users. Should be run by a contab
  7. ## every 15 minutes or so.
  8. ##
  9.  
  10. # Logfile to write deletions: (/dev/null valid)
  11. LOGFILE=/var/adm/flushpop_log
  12.  
  13. # in.pop3d tmp directory:
  14. TMPDIR=/usr/tmp/.pop
  15.  
  16.  
  17.  
  18. ls -l $TMPDIR | awk '{print $9}' >/tmp/.usrtmp
  19. NUMBER=`wc -l /tmp/.usrtmp | awk '{print $1}'`
  20.  
  21. while [ $NUMBER -gt 1 ]
  22. do
  23. USER=`head -$NUMBER /tmp/.usrtmp | tail -1`
  24. ps aux | grep in.pop3d | grep $USER >/tmp/.poptmp
  25. SIZE=`ls -l /tmp/.poptmp | awk '{print $5}'`
  26. if [ $SIZE -eq 0 ] ; then
  27.   echo `date` -- removed stale file for: $USER >> $LOGFILE
  28.   rm -f $TMPDIR/$USER
  29. fi
  30. TMP=`expr $NUMBER - 1`
  31. NUMBER=$TMP
  32. done
  33. rm -f /tmp/{.poptmp,.usrtmp}
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement