Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some problem with sendLine() #63

Open
ppsnumi opened this issue Aug 12, 2019 · 2 comments
Open

some problem with sendLine() #63

ppsnumi opened this issue Aug 12, 2019 · 2 comments

Comments

@ppsnumi
Copy link

ppsnumi commented Aug 12, 2019

Hello

I have some problem with expectit and jsch using expect.sendLine() function
that's error when send "find . -type f \\( -name \"*.1\" -o -name \"*.2\" \\) | wc -l"

origianl command(no java escape) : "find . -type f \( -name "*.1" -o -name "*.2" \) | wc -l"

result error:prompt]find . -type f \( -name "*.1" -name "*.2 prompt]ame "*.1" -name "*.2" <��������������������� \) | wc -l

  1. why entered new line?
  2. what "<��������������������� "

I use expectit-core-0.9.0.jar and jsch-0.1.55.jar and hpux 11.31 ksh

@agavrilov76
Copy link
Owner

Cam you please include a source code snippet? Are you waiting for the prompt after sendLine command?

@ppsnumi
Copy link
Author

ppsnumi commented Sep 16, 2019

`package sshProxy;

import static net.sf.expectit.matcher.Matchers.contains;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;

import net.sf.expectit.Expect;

public class ShellUtils {
public static final String COMMAND_FIND_EXMS_ATTATCH = "find . -type f \( -name ".1"-o -name ".2" \) | wc -l";

public static void countEmxsAttach(DateTime startDate, DateTime endDate, DateTime maxRuntime, String prompt, String path,
		Logger log, Expect expect) throws Exception {

	String result = null;
	String[] lines = null;
	String count = null;
	
	if(startDate.isAfter(endDate)) {
		log.error("time error");
		return;
	}

	// Month
	for (int month = startDate.getMonthOfYear(); month <= 12; month++) {
		int lastDayOfMonth = startDate.dayOfMonth().getMaximumValue();
		for (int day = startDate.getDayOfMonth(); day <= lastDayOfMonth; day++) {
			if (DateTime.now().isAfter(maxRuntime)) {
				log.info("MAX RUNTIME:{}", DateTime.now());
				throw new Exception("time over");
			}

			String baseDir = String.format(path, month, day);
			String curruntDir = prompt + baseDir;
			
			expect.sendLine("cd " + baseDir);
			expect.expect(contains(curruntDir));
			expect.sendLine(COMMAND_FIND_EXMS_ATTATCH);

			result = expect.expect(contains(curruntDir)).getBefore();
			lines = StringUtils.split(result, StringUtils.LF);
			count = StringUtils.trim(lines[1]);

			log.info("ATTATCH:{}\t{}\t{}", baseDir, count);

			startDate = startDate.plusDays(1);
			
			if (startDate.isAfter(endDate)) {
				log.info("MAX RUNTIME:{}", DateTime.now());
				return;
			}
		}

	}

}

}`

main Class call above "countEmxsAttach"
ssh connected and close connection in main class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants