1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.Arrays;
21
22 import org.apache.commons.io.FileUtils;
23 import org.junit.Test;
24
25 public class UnixUtilsTest {
26
27 @Test
28 public void testRsync() {
29 try {
30 String source = "root@env7.ole.kuali.org:/home/tomcat";
31 File destination = new File("/tmp/foo/man/chu/xyz");
32 FileUtils.deleteDirectory(new File("/tmp/foo"));
33 UnixUtils.rsyncdirs(Arrays.asList("--stats"), source, destination);
34 } catch (Exception e) {
35 e.printStackTrace();
36 }
37 }
38
39
40 public void testSsh() {
41 try {
42 File source = new File("/Users/jeffcaddel/Downloads/foo.sh");
43 String destination = "root@env11.ks.kuali.org:/home/tomcat/foo.sh";
44 UnixUtils.sshsu("root@env11.ks.kuali.org", "tomcat", "/home/tomcat/foo.sh");
45 UnixUtils.sshchown("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh");
46 UnixUtils.sshchownr("root@env11.ks.kuali.org", "tomcat", "tomcat", "/home/tomcat/foo.sh");
47 UnixUtils.scp(destination, source);
48 UnixUtils.sshrm("root@env11.ks.kuali.org", "/home/tomcat/foo.sh");
49 UnixUtils.scp(source, destination);
50 UnixUtils.sshmkdir("root@env11.ks.kuali.org", "/home/tomcat/foo.sh");
51 String newDestination = "root@env11.ks.kuali.org:/home/tomcat/foo/bar.sh";
52 UnixUtils.scp(source, newDestination);
53 FileUtils.deleteDirectory(new File("/tmp/tomcat"));
54 UnixUtils.rsync(Arrays.asList("-r", "--stats", "-a"), "root@env11.ks.kuali.org:/home/tomcat/", "/tmp/tomcat");
55 } catch (Exception e) {
56 e.printStackTrace();
57 }
58 }
59
60
61 public void testScp() throws IOException {
62 try {
63 File localFile1 = new File("/Users/jeffcaddel/Downloads/jjj.zip");
64 File localFile2 = new File("/Users/jeffcaddel/Downloads/foo/xyz/jjj.zip");
65 UnixUtils.scp(localFile1, "root@ci.fn.kuali.org:/root/jjj.zip");
66 UnixUtils.scp("root@ci.fn.kuali.org:/root/jjj.zip", localFile2);
67 } catch (Exception e) {
68 e.printStackTrace();
69 }
70 }
71 }