2012-10-16 45 views
5

मुझे स्थानीय मशीन से ज़िप फ़ाइलों की प्रतिलिपि बनाने और दूरस्थ मशीन में पेस्ट करने और दूरस्थ फ़ाइलों में उन फ़ाइलों को अनजिप करने की आवश्यकता है।रिमोट मशीन पर फ़ाइलों को कॉपी और अनजिप करें - चींटी

मुझे पता है कि पहला भाग एसपीपी (स्थानीय से कॉपी ज़िप फ़ाइलों और रिमोट मशीन में पेस्ट) का उपयोग करके किया जा सकता है लेकिन चींटी का उपयोग करके दूसरा भाग कैसे करें?

अग्रिम धन्यवाद

उत्तर

4

में आप sshexec task इस्तेमाल कर सकते हैं दूरस्थ मशीन पर कमांड लाइन unzip आदेश कॉल करने के लिए (रिमोट मशीन संभालने है स्थापित खोलना)।

<!-- local directory containing the files to copy --> 
<property name="archives" location="C:\path\to\zipfiles" /> 
<property name="archives.destination" value="/home/testuser/archives" /> 
<property name="unzip.destination" value="/home/testuser/unpacked" /> 

<fileset id="zipfiles.to.copy" dir="${archives}" includes="*.zip" /> 

<!-- copy the archives to the remote server --> 
<scp todir="${user}:${password}@host.example.com:${archives.destination}"> 
    <fileset refid="zipfiles.to.copy" /> 
</scp> 

<!-- Build the command line for unzip - the idea here is to turn the local 
    paths into the corresponding paths on the remote, i.e. to turn 
    C:\path\to\zipfiles\file1.zip;C:\path\to\zipfiles\file2.zip... into 
    /home/testuser/archives/file1.zip /home/testuser/archives/file2.zip 

    For this to work there must be no spaces in any of the zipfile names. 
--> 
<pathconvert dirsep="/" pathsep=" " property="unzip.files" refid="zipfiles.to.copy"> 
    <map from="${archives}" to="${archives.destination}" /> 
</pathconvert> 

<!-- execute the command. Use the "-d" option to unzip so it will work 
    whatever the "current" directory on the remote side --> 
<sshexec host="host.example.com" username="${user}" password="${password}" 
    command="/bin/sh -c ' 
    for zipfile in ${unzip.files}; do 
     /usr/bin/unzip -d ${unzip.destination} $$zipfile ; done '" /> 

unzip आदेश अन्य विकल्पों में से एक नंबर लेने के लिए, अपने पूर्ण विवरण के लिए man page देख सकते हैं। उदाहरण के लिए -j विकल्प ज़िप फ़ाइलों के अंदर किसी भी निर्देशिका पदानुक्रम को अनदेखा कर देगा और सभी निकाली गई फ़ाइलों को सीधे लक्ष्य निर्देशिका में रखेगा। और -o बिना किसी संकेत के मौजूदा निर्देशिका में मौजूदा फ़ाइलों को ओवरराइट करने के लिए मजबूर करेगा।

+0

क्या आप मुझे उदाहरण दे सकते हैं जहां मुझे सभी फाइलों को एक विशेष डीआईआर में अनजिप करने की आवश्यकता है और उन unzipped फ़ाइल को sshexec का उपयोग करके किसी अन्य डीआईआर में डालना है? – coolgokul

+0

@coolgokul मैंने एक (उम्मीदपूर्वक व्यापक) उदाहरण जोड़ा है। –

+0

भयानक महान। यह ठीक काम कर रहा है। दो सवाल। 1. इस प्रोग्राम को सभी फ़ाइलों को एक फ़ोल्डर में अनजिप करने और निकालने वाली फ़ाइलों को एक निर्देशिका में स्थानांतरित करने के लिए कैसे करें। 2. अगर फाइलें पहले से ही गंतव्य डीआईआर में अनजिप हैं और यदि मैं फिर से अनजिप करने का प्रयास करता हूं तो यह फाइलों को बदलने के लिए कहता है? फाइलों को बदलने के लिए हमेशा हाँ कैसे सेट करें? अग्रिम में धन्यवाद। – coolgokul