में आप 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
बिना किसी संकेत के मौजूदा निर्देशिका में मौजूदा फ़ाइलों को ओवरराइट करने के लिए मजबूर करेगा।
स्रोत
2012-10-16 19:40:22
क्या आप मुझे उदाहरण दे सकते हैं जहां मुझे सभी फाइलों को एक विशेष डीआईआर में अनजिप करने की आवश्यकता है और उन unzipped फ़ाइल को sshexec का उपयोग करके किसी अन्य डीआईआर में डालना है? – coolgokul
@coolgokul मैंने एक (उम्मीदपूर्वक व्यापक) उदाहरण जोड़ा है। –
भयानक महान। यह ठीक काम कर रहा है। दो सवाल। 1. इस प्रोग्राम को सभी फ़ाइलों को एक फ़ोल्डर में अनजिप करने और निकालने वाली फ़ाइलों को एक निर्देशिका में स्थानांतरित करने के लिए कैसे करें। 2. अगर फाइलें पहले से ही गंतव्य डीआईआर में अनजिप हैं और यदि मैं फिर से अनजिप करने का प्रयास करता हूं तो यह फाइलों को बदलने के लिए कहता है? फाइलों को बदलने के लिए हमेशा हाँ कैसे सेट करें? अग्रिम में धन्यवाद। – coolgokul