Linux shares Windows files and automates changing file encodings

Source: Internet
Author: User

Take the K3 log as an example:

  On the K3 database server, do the following:

  1, the database server in K3 Export log data to the local D:/k3log (script automation execution)

  2, set the script scheduled task daily copy the files under D:/k3log to D:/k3log_bak

Eof

Set Filename=d:\test\del.log

Echo (%date%%time%) >>%filename%

D:

CD D:\K3LOG

forfiles/d-l/c "cmd/c del @path"//delete the log of the day before, and keep it as good as before

forfiles/c "cmd/c copy @path D:\K3KOG_BAK"//Copy files generated every day to K3log_bak

forfiles/d -7/c "cmd/c del D:\K3LOG_BAK"//delete backup files from seven days ago

Echo End >>%filename%

Eof

  To operate on Linux:

  1, the general Windows Server on the disk will be shared share the way (most commonly used samba, simple can do it yourself)

  2. Directly mount Windows shared files

#mount-T cifs-o username= user, domain= domain name, password= password//ip/d$/k3log/home/mount_k3log

Note the following: Linux installation cifs.util, password can not have a comma (some words to write to the file or no more command line password, enter after the password), d$ is a shared disk, K3log is the file on the disk, I only need this file to share this file.

If you often need to restart the file, this command is written to/etc/fstab set to boot

  3. Set the timer task shell script

Eof

#!/bin/bash

For i in ' find/home/mount_k3log-name ' *.log '

Do Echo $i

Iconv-f gb2312-t UTF-8 $i-o/home/k3log/' date-d ' yesterday ' + '%y%m%d '. log

Done

find/home/k3log/-mtime +6-name "*.log"-exec rm-rf {} \;

echo "' Date ' + success" >>/home/shell/k3.log

Eof

In fact, it is not so troublesome, this script is a batch operation, but our original file has only one file per day, only need a few commands to complete.

Eof

#!/bin/bash

Iconv-f gb2312-t UTF-8/home/mount_k3log/*.log-o/home/k3log/' date-d "Yesterday" + "%y%m%d" '. Log

find/home/k3log/-mtime +6-name "*.log"-exec rm-rf {} \;

echo "' Date ' + success" >>/home/shell/k3.log

Eof

  4. Execute scripts on a daily schedule

Eof

0 2 * * */home/shell/k3_copy.sh &>>/var/log/cront.log

Eof

Linux shares Windows files and automates changing file encodings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.