Expect는 기본적으로 tcl로 작성됩니다. 하지만 tcl는 그리 친숙한 언어가 아니죠… expect는 다양한 언어에 모듈 형태로 지원되는데, 그중에 그나마 친숙한 perl로 expect를 사용하는 방법입니다.
리눅스에 기본적으로 perl이 설치되어 있겠지만, 혹여나 설치가 되어 있지 않다면 yum이나 apt로 설치합니다.
#sudo apt install perl
Perl는 모듈 관리를 위해 cpan을 이용합니다.
#sudo install cpan
#sudo cpan expect
#!/usr/bin/expect -f
proc usage {} {
puts "usage: ip_address password"
exit 1
}
proc login { host user password } {
puts "Connect server...\n"
spawn ssh $user@$host
expect {
-re "No route" { exit 1 }
-re "try again" { exit 1 }
-re "yes/no" { send "yes\r"; exp_continue }
-re "password:" { send "$password\r"; }
}
send "exit";
}
set timeout -1
set HOST [lindex $argv 0]
set USERID [lindex $argv 1]
set PASSWD [lindex $argv 2]
set argc [llength $argv]
if { [llength $argv] != 3 } {
usage
}
set running [login $HOST $USERID $PASSWD ]
exit 0
#!/usr/bin/env perl
use strict;
use warnings;
use Expect;
my $host = $ARGV[0];
my $userid = $ARGV[1];
my $userpass = $ARGV[2];
my $exp = Expect->new;
$exp->spawn("ssh", $userid . "@" . $host);
$exp->expect(
10,
[ qr/(yes\/no)/ => sub { my $exp = shift; $exp->send("yes\n"); exp_continue; } ],
[ qr/password:/ => sub { my $exp = shift; $exp->send($userpass."\n"); exp_continue; } ],
[ qr/$userid.*\$/ => sub { my $exp = shift; $exp->send("ls > ls.txt\n");} ],
[ qr/Password:/ => sub { my $exp = shift; $exp->send($userpass."\n"); exp_continue; } ],
[ qr/root.*#/ => sub { my $exp = shift; $exp->interact(); } ],
);
print "$0 exit\n";
Introduction : Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications. And by adding Tk, you can also wrap interactive applications in X11 GUIs.
Expect can make easy all sorts of tasks that are prohibitively difficult with anything else. You will find that Expect is an absolutely invaluable tool - using it, you will be able to automate tasks that you’ve never even thought of before - and you’ll be able to do this automation quickly and easily.
출처:https://core.tcl-lang.org/expect/index
Telnet, FTP, SSH 등과 같은 응용 프로그램을 자동으로 상호작용하며 제어하기 위한 프로그램입니다.
국내에는 Expect를 많이 사용하지 않는지, 관련 자료들이 그리 많지 않네요…
그 중 제타위키에 Expect가 어떤건지 이해하기 좋은 예제들이 잘 정리되어 있습니다.(제타위키:expect)
Expect는 Sourceforge.net에서 다운로드 가능하며, 리눅스에서는 간단하게 yum이나 apt로 설치 가능합니다.
#sudo apt install expect
Expect는 다양한 도구들을 제공합니다.
#sudo apt install expect-dev
IN 연산자는 보통 특정 Table(or View) Data에서 데이터를 추출하기 위해 사용합니다. 이를 응용하여 해당 테이블에 IN에서 지정된 데이터가 있는지 확인하는 용도로도 사용됩니다.
select count(*) from data in (~~~)
하지만 IN에 지정되는 값을 모두 확인하기 때문에 IN에 지정된 데이터가 많아질 수록 느려질 수 밖에 없습니다.
서브 쿼리를 만족하면 그 즉시 해당 데이터를 반환합니다.
EXISTS는 IN과 다르게 서브 쿼리를 이용하며, 서브 쿼리에는 검사하고자 하는 조건이 포함되어야 합니다.
select * from ([데이터 A] where exists ([데이터 B]) B where [조건]);
다음처럼 List 형태의 데이터를 가지고 있는 테이블이 있습니다.
next_approval_approval_id에 데이터가 있는데, 해당 데이터가 가리키는 데이터 없는 경우 문제가 발생합니다.
해서, next_approaval_approval_id이 가리키는 approval_id가 없는 경우 찾고자 합니다.
select A.next_approval_approval_id from
(select * from tb_approval where next_approval_approval_id is not null) A where not exists
(select * from (select * from tb_approval) B where A.next_approval_approval_id = B.approval_id);
(없는 경우를 찾고자 했으므로, not exists를 사용하였습니다.)
===
: Edit the sudoers file
sudoers 파일을 수정하기 위한 유틸리티입니다.
sudo 권한은 일반 유저에게 root 권한을 부여하는 것입니다. sudo 권한을 부여하기 위해서는 sudoers 파일을 수정해야 하는데, 그만큼 중요한 파일이기에 파일 권한이 잠겨 있습니다.
다른 계정은 읽지도 못하며, 소유자인 root도 읽기만 가능합니다.
그렇기에 sudo 권한을 부여하기 위해선
======================
STS + Spring Boot 환경에서 Documsnts4j를 이용하여 Docx를 PDF로 변환하는 코드를 구현하였습니다.
STS의 개발 환경에서 구현하다 보니 Embedded Tomcat에서는 잘 동작하는데, 막상 서비스를 위해 Tomcat에 배포를 하니 Documtns4j의 Convert가 제대로 수행되지 않았습니다.
Convert 수행시 Exception는 다음과 같습니다.
com.documents4j.throwables.ConverterAccessException: The converter seems to be shut down
at com.documents4j.util.Reaction$ConverterAccessExceptionBuilder.make(Reaction.java:117) ~[documents4j-util-all-1.0.2.jar:na]
at com.documents4j.util.Reaction$ExceptionalReaction.apply(Reaction.java:75) ~[documents4j-util-all-1.0.2.jar:na]
at com.documents4j.conversion.ExternalConverterScriptResult.resolve(ExternalConverterScriptResult.java:70) ~[documents4j-transformer-api-1.0.2.jar:na]
at com.documents4j.conversion.ProcessFutureWrapper.evaluateExitValue(ProcessFutureWrapper.java:48) ~[documents4j-util-transformer-process-1.0.2.jar:na]
at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:36) ~[documents4j-util-transformer-process-1.0.2.jar:na]
at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:11) ~[documents4j-util-transformer-process-1.0.2.jar:na]
at com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:78) ~[documents4j-util-conversion-1.0.2.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_74]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_74]
at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_74]
Documnts4j는 VBScript를 이용하여 변환을 수행합니다.
4:36:16.109 INFO c.d.c.msoffice.MicrosoftWordBridge - From-Microsoft-Word-Converter was started successfully
14:36:16.112 INFO com.documents4j.job.LocalConverter - The documents4j local converter has started successfully
14:36:16.124 INFO c.d.c.msoffice.MicrosoftWordBridge - Requested conversion from C:\Users\gmpark\AppData\Local\Temp\1575264973533-0\68ed3e6b-ab29-47ff-8ee5-fafebe14c5a6\temp1 (application/vnd.com.documents4j.any-msword) to C:\Users\gmpark\AppData\Local\Temp\1575264973533-0\68ed3e6b-ab29-47ff-8ee5-fafebe14c5a6\temp2 (application/vnd.com.documents4j.pdf-a)
MicrosoftWordBridge가 정상적으로 수행되었고, VBScript도 정상적으로 생성하였습니다.
먼저, 해당 VBScript가 정상적으로 수행되는지 확인해봅니다.
(대상 파일 : C:\test.docx, 결과 파일 : C:\test.pdf, 변환 포맷 : 999(PDFA)
cd C:\Users\gmpark\AppData\Local\Temp\1575264973533-0
script word_convert754050868.vbs C:\test.docx C:\test.pdf 999
정상적으로 변환이 되네요…
Documents4j가 생성해준 VBScription는 이상이 없으니, Java에서 실행시켜주는게 문제일 것 같네요.
STS 환경에선 정상적으로 수행이 됬으니, Tomcat 설정을 확인해봅니다.
Tomcat은 기본적으로 Local Service account로 실행되도록 설정이 되어 있네요.
해당 설정을 Local System account로 변경하고 재시작하였습니다.
정상적으로 수행이 되네요!!
Tomcat이 Local Service accout 권한인 경우 Word를 실행시키지 못해 발생하는 문제인 것 같네요.
앞으로 Tomcat으로 배포시 유의해야 할 것 같습니다
|-- 국가기술자격
| |-- 한국산업인력공단
| | |-- 멀티미디어콘텐츠제작전문가
| | |-- 사무자동화산업기사
| | |-- 전자계산기조직응용기사
| | |-- 정보관리기술사
| | |-- 정보기기운용기능사
| | |-- 정보처리기능사
| | |-- 정보처리기사
| | |-- 정보처리산업기사
| | |-- 컴퓨터시스템응용기술사
| |-- 대한상공회의소
| | |-- 워드프로세서
| | |-- 전산회계운용사
| | |-- 전자상거래관리사
| | |-- 전자상거래운용사
| | |-- 컴퓨터활용능력
| | |-- 한국인터넷진흥원
| | |-- 정보보안기사
| | |-- 정보보안산업기사
| |-- 한국콘텐츠진흥원
| | |-- 게임그래픽전문가
| | |-- 게임기획전문가
| | |-- 게임프로그래밍전문가
|-- 국가공인자격
| |-- 한국정보통신진흥협회
| | |-- 공무원정보이용능력평가(NIT)
| | |-- 디지털정보활용능력(DIAT)
| | |-- 리눅스마스터
| | |-- 인터넷정보관리사
| |-- 한국정보평가협회
| | |-- CS Leaders(관리사)
| | |-- PC Master(정비사)
| |-- 피씨티
| | |-- PC활용능력평가시험(PCT)
| |-- 대한상공회의소
| | |-- 컴퓨터운용사
| |-- 대한정보통신기술
| | |-- 정보기술프로젝트관리전문가(IT-PMP)
| |-- 한국데이터베이스진흥원
| | |-- SQL
| | |-- 데이터분석전문가
| | |-- 데이터분석준전문가
| | |-- 데이터아키텍처전문가(DAP)
| |-- 한국사물인터넷협회
| | |-- RFID기술자격검정(RFID-GL/RFID-SL)
| |-- 한국정보통신자격협회
| | |-- PC정비사
| | |-- 네트워크관리사
| |-- 한국정보화진흥원
| | |-- 정보시스템감리사
|-- 국제전문자격
| |-- Cisco
| | |-- Cisco Certified Network Associate(CCNA)
| | |-- Cisco Certified network Professional(CCNP): Routing and Switching
| | |-- Cisco Certified network Professional(CCNP): Collabroration
| | |-- Cisco Certified network Professional(CCNP): Data Center
| | |-- Cisco Certified network Professional(CCNP): Cluod
| | |-- Cisco Certified network Professional(CCNP): Security
| | |-- Cisco Certified network Professional(CCNP): Wireless
| | |-- Cisco Certified network Professional(CCNP): Service Provider
| | |-- Cisco Certified Internetwork Expert(CCIE): Enterprise Infrastructure
| | |-- Cisco Certified Internetwork Expert(CCIE): CCIE Enterprise Wireless
| | |-- Cisco Certified Internetwork Expert(CCIE): Data Center
| | |-- Cisco Certified Internetwork Expert(CCIE): Security
| | |-- Cisco Certified Internetwork Expert(CCIE): service Provider
| | |-- Cisco Certified Architect
| |-- IBM
| | |-- IBM Certified Systems Expert
| | |-- IBM Certified Advanced Technical Expert
| | |-- IBM Certified System Administrator
| |-- Microsoft
| | |-- Microsoft Certified Professional(MCP)
| | |-- Microsoft Certified Solutions Associate(MCSA): BI Reporting
| | |-- Microsoft Certified Solutions Associate(MCSA): Microsoft Dynamics 365 for Operations
| | |-- Microsoft Certified Solutions Associate(MCSA): Office 365
| | |-- Microsoft Certified Solutions Associate(MCSA): SQL 2016 BI Development
| | |-- Microsoft Certified Solutions Associate(MCSA): SQL 2016 Database Administration
| | |-- Microsoft Certified Solutions Associate(MCSA): SQL 2016 Database Development
| | |-- Microsoft Certified Solutions Expert(MCSE): Business Applications
| | |-- Microsoft Certified Solutions Expert(MCSE): Core Infrastructure
| | |-- Microsoft Certified Solutions Expert(MCSE): Data Management and Analytics
| | |-- Microsoft Certified Solutions Expert(MCSE): Mobility
| | |-- Microsoft Certified Solutions Expert(MCSE): Productivity
| | |-- Microsoft Office Specialist(MOS)
| | |-- Microsoft Technology Associate(MTA)
| | |-- Microsoft Professional Program(MPP)
| |-- Google
| | |-- Google Analytics Individual Qualification(GAIQ)
| |-- Oracle
| | |-- Oracle Certified Junior Associate(OJA)
| | |-- Oracle Certified Associate(OCA)
| | | |-- Oracle Database Administrator Certified Associate
| | | |-- Oracle PL/SQL Developer Certified Associate
| | | |-- Oracle Database SQL Certified Associate
| | | |-- Oracle Certified Associate, Java Programmer
| | |-- Oracle Certified Professional(OCP)
| | | |-- Oracle Database Administration Certified Professional
| | | |-- Oracel Database PL/SQL Developer Certified Professional
| | | |-- Oracle Certified Professional, MySQL Database Administrator
| | | |-- Oracle Certified Professional, MySQL Developer
| | | |-- Oracle Certified Professional: Java SE Developer
| | | |-- Oracle Certified Professional, Java EE Application Developer
| | |-- Oracle Certified Master(OCM)
| | | |-- Oracle Database Administration Certified Master
| | | |-- Oracle Certified Master, Java EE Enterprise Architect
| | |-- Oracle Certified Specialist(OCS)
| | | |-- Oracle Identity Governance Suite 11g PS3 Certified Implementation Specialist
| | | |-- Oracle Database 12c Certified Implementation Specialist
| | | |-- Oracle Real Application Clusters 12c Certified Implementation Specialist
| | |-- Oracle Certified Expert(OCE)
| | | |-- Oracle Certified Expert, Oracle Database 12c: Performance Management and Tuning
| | | |-- Oracle Certified Expert, Oracle Database 12c: RAC and Grid Infrastructure Administrator
| | | |-- Oracle Database 12c Maximum Availability Certified Expert
| | | |-- Oracle Database 12c Maximum Availability Certified Master
| |-- Adobe
| | |-- Adobe Certified Associate(ACA)
| |-- Autodesk
| | |-- Autodesk Certified User(ACU)
| | |-- Autodesk Certified Professional(ACP)
| |-- CompTIA
| | |-- CompTIA netowrk+
| | |-- CompTIA Linux
| | |-- CompTIA Server+
| | |-- CompTIA Storage+
| | |-- CompTIA Mobile App Security+
| | |-- CompTIA Security+
| | |-- CompTIA Advanced Security Practitioner
| | |-- CompTIA Strata IT Fundamentals
| | |-- CompTIA A+
| | |-- CompTIA CDIA+
| | |-- CompTIA Cloud+
| | |-- CompTIA CTT+
| | |-- CompTIA Mobility+
| | |-- CompTIA Project+
| | |-- CompTIA Cloud Essentials
| | |-- CompTIA Healthcare IT Technician
| |-- LPI
| | |-- Linux Essentials
| | |-- LPIC1 Linux administratior
| | |-- LPIC2 Linux Engineer
| | |-- LPIC3 Enterprise professional(Mixed Environment/Security/Virtualization&HA)
| |-- Redhat
| | |-- Red Hat Certified System Administrator(RHCSA)
| | |-- Red Hat Certified Engineer(RHCE)
| | |-- Red Hat Certified Architect(RHCA)
| | | |-- Red Hat Certified Architeca(RHCA) in Infrastructure
| | | | |-- Red Hat Certified System Administrator in Red Hat OpenStack
| | | | |-- Red Hat Certified Specialist In Hybrid Cloud Management
| | | | |-- Red hat Certified Specialist in Containerized Application Development
| | | | |-- Red Hat Certified Specialist in OpenShift Administration
| | | | |-- Red Hat Certified Engineer in Red Hat OpenStack
| | | | |-- Red Hat Certified Virtualization Administrator
| | | | |-- Red Hat Certified Specialist in Linux Diagnostics and Troubleshooting
| | | | |-- Red Hat Certified Specialist in Deployment and Systems Management
| | | | |-- Red Hat Certified Specialist in Configuration Management
| | | | |-- Red Hat Certified Specialist in Ansible Automation
| | | | |-- Red Hat Certified Specialist in Server Security and Hardening
| | | | |-- Red Hat Certified Specialist in High Availability Clustering
| | | | |-- Red Hat Certified Specialist in Linux Performance Tuning
| | | | |-- Red Hat Certified Specialist in Security: Linux
| | | | |-- Red Hat Certified Specialist in OpenShift Application Development
| | | |-- Red Hat Certified Architect(RHCA) in Enterprise Applications
| | | | |-- Red Hat Certified Specialist in Enterprise Application Server Administration
| | | | |-- Red Hat Certified Specialist in Containerized Application Development
| | | | |-- Red Hat Certified Specialist in OpenShift Administration
| | | | |-- Red Hat Certified Specialist in Configuration Management
| | | | |-- Red Hat Certified Specialist in Ansible Automation
| | | | |-- Red Hat Certified Specialist in Camel Development
| | | | |-- Red Hat Certified Specialist in Fast-Cache Application Development
| | | | |-- Red Hat Certified Specialist in Business Rules
| | | | |-- Red Hat Certified Specialist in Business Process Design
| | | | |-- Red Hat Certified Specialist in OpenShift Application Development
| | |-- Red Hat Certified Engineer in Red Hat OpenStack
| | |-- Red Hat Certified Enterprise Application Developer
| | |-- Red Hat Certified Enterprise Microservices Developer
| | |-- Red Hat Certified System Administrator in Red Hat OpenStack
| |-- C++ Insitute
| | |-- C Programming Language Certification Assiociate
| | |-- C++ Certified Assiociate Programmer
| | |-- C++ Certified Professional Programmer