Linux mount Windows directory

【Problem Description】

 

The Windows machine 192.168.1.103 shares the /share/yasi directory and has been given write permission, and can log in with yasi/pass under the Windows machine. Trying to mount the shared directory to /mnt/yasi on a CentOS 6.3 machine

 

[plain]  view plain copy  
 
  1. mount -t cifs //192.168.1.103/share/yasi /mnt/yasi -o username="yasi",password="pass"  


The result failed with the following error message:

 

 

[plain]  view plain copy  
 
  1. mount: block device //192.168.1.103/share/yasi is write-protected, mounting read-only  
  2. mount: cannot mount block device //192.168.1.103/share/yasi read-only  



 

【reason】

Need to install cifs-utils

 

【solve】

Install cifs-utils

 

[plain]  view plain copy  
 
  1. yum install cifs-utils.x86_64  


then re-execute

 

 

[plain]  view plain copy  
 
  1. mount -t cifs //192.168.1.103/share/yasi /mnt/win -o username="yasi",password="pass"  

On mount, and have write permissions.

 

 

[Do something with Windows shared directories on Linux mounts]

 

For the rational use of resources, the company imposes the following restrictions on a shared folder: In the personal folders of employees under this folder, files or subfolders whose last modified/access time is older than 30 days will be deleted. Deleted in a script that is executed regularly every day. However many files are large and we don't want to be deleted.

Below, the counterattack of Diaosi:

 

1) Mount the personal folder under the shared folder (such as //192.168.1.103/share/yasi) to a Linux machine

 

[plain]  view plain copy  
 
  1. mount -t cifs //192.168.1.103/share/yasi /mnt/yasi -o username="yasi",password="pass"  

 

 

2) Code the following Python script on the Linux machine, /home/yasi/update_ts.py

 

[python]  view plain copy  
 
  1. import os, sys, time  
  2.   
  3. topdir = "/mnt/yasi"  
  4.   
  5. def update_time(timestamp, dirname, names):  
  6.         for name in names:  
  7.                 timestamps = (timestamp, timestamp)  
  8.                 os.utime(os.path.join(dirname, name), timestamps)  
  9.   
  10. os.path.walk(topdir, update_time, time.time())  


3) Add a cron job on the Linux machine as follows, that is, execute the update_ts.py script at 23:00 every day

 

crontab -e

 

[plain]  view plain copy  
 
  1. 0 23 * * * python /home/yasi/update_ts.py  


Therefore, at 23:00 every day, the last modified/access time of all files and subfolders under //192.168.1.103/share/yasi will be changed to the current time, so that there will never be a "no access for more than 30 days". Files and folders are gone!

 

 

【Notice】

 

All files and subfolders in /mnt/yasi specified in update_ts.py, that is, //192.168.1.103/share/yasi, will be timestamped, but the timestamp of the folder //192.168.1.103/share/yasi itself Not modified by update_ts.py.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324979877&siteId=291194637