Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ CentOS achieve trash mechanism     - Ordinary users how the Linux system shutdown (Linux)

- impdp error ORA-39001, ORA-39000, ORA-31619 (Database)

- Linux kernel VLAN study notes (Programming)

- UUID in Java (Programming)

- C language function pointer and a callback function (Programming)

- Installation Enpass secure password manager on Ubuntu (Linux)

- High-performance JavaScript loaded and executed (Programming)

- Command-line based tools for better alternatives (Linux)

- Enterprise Hadoop cluster architecture - DNS installation (Server)

- Linux system started to learn: Teaches you install Ubuntu 15.04 on VirtualBox (Linux)

- 11G ASM disk group does not automatically handle MOUNT (Database)

- Installation of Gitlab under Ubuntu (Linux)

- To_teach you three strategies to prevent the LAN IP address theft (Linux)

- Golang use Oracle database on Ubuntu 14.04 (Linux)

- RHEL5 establish a local yum source (Linux)

- Linux uses shared memory communication process synchronization Withdrawal (Programming)

- Linux System Getting Started Tutorial: How do you know Shell which is currently being used (Linux)

- How to create a someone project on github (Linux)

- Linux System Getting Started Learning: hard disk partition, and to deal with traps (Linux)

- Use MD5 transform algorithm to prevent exhaustive decipher passwords (Linux)

 
         
  CentOS achieve trash mechanism
     
  Add Date : 2018-11-21      
         
         
         
  As an operation and maintenance personnel, when you delete files on the server in order to facilitate direct use often rm * .txt such a wildcard, in order to save even add -rf argument, if it is determined, then okay, if in time to delete an inattentive, that things may become significant.

As the saying goes often in the river station defiled, no one can guarantee that you can not make a mistake, but every day in fear of the whole into an obsessive-compulsive disorder is not a thing, so I think on the whole a similar Linux servers Win the Recycle Bin feature.

The following is the script I realized the Recycle Bin, the Recycle Bin is enabled, if you need to delete a file, simply execute "del file name / folder name" to

1 [root @ localhost tools] # tree Trash_1.0 /
2 Trash_1.0 /
3 install_Trash.sh
4 Trash_mkdir.sh

Very simple, two script files, Trash_mkdir.sh is written crontab scheduled tasks in the content, responsible for generating a corresponding date day Trash folder and periodically clean up trash more than five days of the document, that the trash can within five days to retain files you delete, install_Trash.sh automatic configuration script is responsible for regular tasks, user personalization loading configuration.

Trash_mkdir.sh content:

[Root @ localhost Trash_1.0] # cat Trash_mkdir.sh
#! / Bin / bash
month = `date" +% m "` # Get the current month
day = `date" +% d "` # get the current date

last_day = `date -d" -1 day "" +% d "` # Get the day before the month
last_day_m = `date -d" -1 day "" +% m "` # Get the day before the date of

del_day = `date -d" -5 day "" +% d "` # get five days in January
del_day_m = `date -d" -5 day "" +% m "` # Get date five days ago

Trash_dir = "/ tmp / del_bak" # Trash List
tmp_dir = "/ tmp / del_bak / tmp" # delete files daily storage directory
# The following is to create the appropriate directory, and give 777 15 if [! -d $ Trash_dir]
then
    / Bin / mkdir -p $ Trash_dir
    / Bin / chmod 777 $ Trash_dir
fi

if [! -d $ tmp_dir]
then
    / Bin / mkdir -p $ tmp_dir
    / Bin / chmod 777 $ tmp_dir
fi

if [! -d / tmp / del_bak / $ month]
then
    / Bin / mkdir / tmp / del_bak / $ month
    / Bin / chmod 777 / tmp / del_bak / $ month
fi

if [! -d / tmp / del_bak / $ month / $ day]
then
    / Bin / mkdir / tmp / del_bak / $ month / $ day
    / Bin / chmod 777 / tmp / del_bak / $ month / $ day
fi

Trash_file = `/ bin / ls -A $ tmp_dir`

if [ "$ Trash_file"! = ""] # This is the timing in every morning to remove the file into the directory last month and date have been classified under the guarantee / tmp / del_bak / tmp catalog store only files deleted day
then
    cd $ tmp_dir
    if [! -d / tmp / del_bak / $ last_day_m / $ last_day /]
    then
      / Bin / mkdir -p / tmp / del_bak / $ last_day_m / $ last_day /
    fi
    / Bin / mv $ tmp_dir / * / tmp / del_bak / $ last_day_m / $ last_day /
fi

if [-d $ Trash_dir / $ del_day_m / $ del_day /] # clean up deleted files five days
then
    cd $ Trash_dir / $ del_day_m / $ del_day / && {
    / Bin / rm -rf $ Trash_dir / $ del_day_m / $ del_day /
    }
fi

install_Trash.sh contents of the script:

[Root @ localhost Trash_1.0] # cat install_Trash.sh
#! / Bin / bash
USER = `/ usr / bin / whoami` # Get the current user
Path TOOLS = "/ usr / local / tools" # scripts stored Trash_mkdir.sh regular tasks can be modified according to their own personal
HOME_DIR = `/ bin / grep" $ USER "/ etc / passwd | awk -F": " '{print $ 6}'` # Get the current user's home directory
CONF = $ HOME_DIR "/. Bashrc" # stitching current user profile path
Trash = `/ bin / grep" del "$ CONF` # has been configured to determine whether the mechanism of trash

if [ "$ Trash" = ""] # Add alias del Trash
then
    echo "alias del = 'mv -t / tmp / del_bak / tmp / --backup = t'" >> $ CONF
fi

if [! -d $ TOOLS]
then
    / Bin / mkdir -p $ TOOLS
fi

/ Bin / cp Trash_mkdir.sh $ TOOLS # copy scheduled tasks script to a specified directory
/ Bin / chmod + x $ TOOLS / Trash_mkdir.sh

if [-z "` grep 'Trash_mkdir.sh' / var / spool / cron / root` "] # crontab task in judging whether the timing has added a trash script
then
    echo "10 0 * * * $ TOOLS / Trash_mkdir.sh" >> / var / spool / cron / root
fi

/ Bin / sh $ TOOLS / Trash_mkdir.sh # initialize Trash

Deployment instructions:

1, the two scripts in the same directory

2, using the Recycle Bin feature you need to enable users to perform install_Trash.sh script to a key installation

Above is my trash mechanism on CentOS6.5 server implementations, interested friends can discuss improvements.
     
         
         
         
  More:      
 
- Java string intern constant pool resolution Introduction (Programming)
- Linux common network tools: batch scanning of hosting services netcat (Linux)
- Java is simple to read and write HDFS Demo (Programming)
- Linux / Raspberry Pi using the following command-line based web browser (Linux)
- Python image processing library (PIL) to install and simple to use (Linux)
- Linux FAQ - How to fix tar:Exitingwith failure status due to previous errors (Linux)
- Linux kernel to achieve soft RPS network to receive soft interrupt load balancing to distribute (Linux)
- Linux Security Raiders SSH tools SCP uses examples to explain in detail (Linux)
- Java logging performance of those things (Programming)
- TNS-03505 name could not be resolved (Database)
- Ubuntu 14.10 / 14.04 / 12.04 How to install Kodi 14.0 RC3 (Linux)
- Sniffer Linux Environment (Linux)
- Linux file time Comments ctime mtime atime (Linux)
- Using Linux stat command to view the files (Linux)
- CentOS 6.6 running level (Linux)
- Struts2 study notes -Valuestack (value stack) and OGNL expression (Programming)
- DataGuard a hardware issue warnings found (Database)
- How to modify the Ubuntu terminal user name changed to red color (Linux)
- To install network scanning and packet sniffer tool Nmap 7.00 under ubuntu (Linux)
- CentOS yum install LAMP (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.