【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
- mount -t cifs //192.168.1.103/share/yasi /mnt/yasi -o username="yasi",password="pass"
The result failed with the following error message:
- mount: block device //192.168.1.103/share/yasi is write-protected, mounting read-only
- mount: cannot mount block device //192.168.1.103/share/yasi read-only
【reason】
Need to install cifs-utils
【solve】
Install cifs-utils
- yum install cifs-utils.x86_64
then re-execute
- 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
- 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
- import os, sys, time
- topdir = "/mnt/yasi"
- def update_time(timestamp, dirname, names):
- for name in names:
- timestamps = (timestamp, timestamp)
- os.utime(os.path.join(dirname, name), timestamps)
- 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
- 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.