1. Docker란

Docker는 애플리케이션을 개발, 전송 및 실행하기 위한 개방형 플랫폼입니다. Docker를 사용하면 애플리케이션을 인프라에서 분리할 수 있으므로 소프트웨어를 빠르게 제공할 수 있습니다. Docker를 사용하면 애플리케이션을 관리하는 것과 동일한 방식으로 인프라를 관리할 수 있습니다. 코드를 신속하게 배송, 테스트 및 배포하기 위한 Docker 방법론을 활용하면 코드 작성과 프로덕션 환경에서 실행하는 사이의 지연을 크게 줄일 수 있습니다.

 

2. Docker 설치

Install using the repository

시스템에 처음으로 Docker Engine을 설치할 경우 먼저 Docker 저장소를 설정해야 합니다. 그런 다음 저장소에서 Docker를 설치하고 업데이트할 수 있습니다.

apt 패키지 인덱스를 업데이트하고 apt가 HTTPS를 통해 리포지토리를 사용할 수 있도록 패키지를 설치합니다.

Set up the repository

apt 패키지 인덱스를 업데이트하고 apt가 HTTPS를 통해 리포지토리를 사용할 수 있도록 패키지를 설치합니다

$ sudo apt-get update

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Docker의 공식 GPG 키 추가:

- debian linux

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

- ubuntu linux

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

 

다음 명령어를 사용하여 저장소를 설정합니다. nightly 또는 test 리포지토리를 추가하려면 아래 명령에서 stable이라는 단어 뒤에 nightly 또는 test(또는 둘 다)라는 단어를 추가합니다.

- debian linux

$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

- ubuntu linux

 echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

 

Dokcer Engine 설치

apt 패키지 인덱스를 업데이트하고 최신 버전의 Docker Engine 및 containerd를 설치하거나 특정 버전을 지정하여 설치합니다.

 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

 

특정 버전의 Docker Engine을 설치하려면 리포지토리에 사용 가능한 버전을 나열한 다음 다음을 선택하여 설치합니다.
a. 리포지토리에서 사용 가능한 버전 나열:

$ apt-cache madison docker-ce

  docker-ce | 5:18.09.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
  docker-ce | 5:18.09.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
  docker-ce | 18.06.1~ce~3-0~debian        | https://download.docker.com/linux/debian stretch/stable amd64 Packages
  docker-ce | 18.06.0~ce~3-0~debian        | https://download.docker.com/linux/debian stretch/stable amd64 Packages

 

b. 두 번째 열의 버전을 사용하여 특정 버전을 설치합니다(예: 5:18.09.1~3-0~debian-stretch ).

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

 

hello-world 이미지를 실행하여 Docker 엔진이 올바르게 설치되었는지 확인합니다.

이 명령은 docker 이미지를 다운로드하고 컨테이너를 실행합니다.

$ sudo docker run hello-world

 

docker ps -a 명령어로 다운로드한 이미지를 확인할 수 있다.

$ sudo docker ps -a 

CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES
bc2e365fdd8d   hello-world   "/hello"   17 minutes ago   Exited (0) 17 minutes ago             reverent_nash

 

일반 유저로 도커명령어 실행

  1. docker를 사용할 user를 docker 그룹에 추가합니다.(참고 docker를 설치하면 docker group 이 생성됩니다.)
    sudo usermod -aG docker $USER
  2. 추가된 그룹을 적용하기 위해 로그아웃했다가 다시 로그인합니다. 또는 아래와 같이 명령어를 수행하여 변경된 그룹을 적용합니다.
 newgrp docker

 

 

Docker Engine 삭제

Docker 엔진, CLI 및 Containerd 패키지를 제거합니다.

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io

 

호스트의 이미지, 컨테이너, 볼륨 또는 사용자 지정 구성 파일은 자동으로 제거되지 않습니다. 아래 명령어로 모든 이미지, 컨테이너 및 볼륨을 삭제합니다.

$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

편집된 구성 파일은 수동으로 삭제해야 합니다.

 

 

 

Recovery Manager Architecture

About Recovery Manager (RMAN)

RMAN(Recovery Manager)은 오라클 데이터베이스 백업 및 복구를 수행할 수 있는 도구이다. 별도의 설치가 필요없는 오라클 데이터베이스 기능이다.

RMAN은 수행한 메타정보를 target database의 control file이나 recovery catalog 에 저장한다. command-line이나 EM(Enterprise Manage) GUI로 RMAN을 수행할 수 있다.

 

About the RMAN Environment

RMAN은 백업/복구에 필요한 여러 application으로 구성되어 있다.

 

Table 3-1 Components of the RMAN Environment

Component Description
RMAN client The client application that manages backup and recovery operations for a target database. The RMAN client can use Oracle Net to connect to a target database, so it can be located on any host that is connected to the target host through Oracle Net.
target database A database containing the control files, datafiles, and optional archived redo logs that RMAN backs up or restores. RMAN uses the target database control file to gather metadata about the target database and to store information about its own operations. The work of backup and recovery is performed by server sessions running on the target database.
recovery catalog database A database containing a recovery catalog, which contains metadata that RMAN uses to perform backup and recovery. You can create one recovery catalog that contains the RMAN metadata for multiple target databases. Unless you are using RMAN with a physical standby database, a recovery catalog is optional when using RMAN because RMAN stores its metadata in the control file of each target database.
recovery catalog schema The user within the recovery catalog database that owns the metadata tables maintained by RMAN. RMAN periodically propagates metadata from the target database control file into the recovery catalog.
physical standby database A copy of the primary database that is updated with archived redo logs generated by the primary database. A physical standby database has the same DBID and DB_NAME values as the primary database, but a different DB_UNIQUE_NAME. You can fail over to the standby database if the primary database becomes inaccessible.
RMAN can create, back up, or recover a standby database. Backups that you make at a standby database are usable at primary database or another standby database for same production database. The recovery catalog is required when you use RMAN in the Data Guard environment.
Note: A logical standby database is treated as a separate database by RMAN because it has a different DBID from its primary database.
See Also: Oracle Data Guard Concepts and Administration to learn how to use RMAN in a Data Guard environment
duplicate database A copy of the primary database that you can use for testing purposes. The DBID is different from the database from which it was created.
fast recovery area A disk location that you can use to store recovery-related files such as control file and online redo log copies, archived redo logs, flashback logs, and RMAN backups. Oracle Database and RMAN manage the files in the fast recovery area automatically.
media manager A vendor-specific application that enables RMAN to back up to a storage system such as tape
media management catalog A vendor-specific repository of metadata about a media management application
Oracle Enterprise Manager A browser-based interface to the database, including backup and recovery through RMAN

RMAN Environment

 

RMAN Command-Line Client

Use the RMAN command-line client to enter commands that you can use to manage all aspects of backup and recovery operations. RMAN uses a command language interpreter that can execute commands in interactive or batch mode. Even when you use the backup and recovery features in Enterprise Manager that are built on top of RMAN, an RMAN client executes behind the scenes.

 

RMAN Channels

The RMAN client directs database server sessions to perform all backup and recovery tasks. What constitutes a session depends on the operating system. For example, on Linux, a server session corresponds to a server process, whereas on Windows it corresponds to a thread within the database service.

RMAN Channels

Channels and Devices

The RMAN-supported device types are disk and SBT (system backup to tape). An SBT device is controlled by a third-party media manager. Typically, SBT devices are tape libraries and tape drives.

If you use a disk channel for a backup, then the channel creates the backup on disk in the file name space of the target database instance creating the backup. You can make a backup on any device that can store a datafile. RMAN does not call a media manager when making disk backups.

To create backups on nondisk media, you must use media management software such as Oracle Secure Backup and allocate channels supported by this software. RMAN contacts the media manager whenever the channel type allocated is not disk. How and when the SBT channels cause the media manager to allocate resources is vendor-specific. Some media managers allocate resources when you issue the command; others do not allocate resources until you open a file for reading or writing.

Automatic and Manual Channels

You can use the CONFIGURE CHANNEL command to configure channels for use with disk or tape across RMAN sessions. This technique is known as automatic channel allocation. RMAN comes preconfigured with one DISK channel that you can use for backups to disk.

When you run a command that can use automatic channels, RMAN automatically allocates the channels with the options that you specified in the CONFIGURE command. For the BACKUP command, RMAN allocates only the type of channel required to back up to the specified media. For the RESTORE command and RMAN maintenance commands, RMAN allocates all necessary channels for the device types required to execute the command. RMAN determines the names for automatic channels.

You can also manually allocate channels. Each manually allocated channel uses a separate connection to the database. When you manually allocate a channel, you give it a user-defined name such as dev1 or ch2.

The number of channels available for use with a device when you run a command determines whether RMAN reads from or write to this device in parallel while performing the command. When the work is done in parallel, the backup of the files is done by more than one channel. Each channel may back up more than one file, but unless a multisection backup is performed, no file is backed up by more than one channel.

RMAN Repository

The RMAN repository is the collection of metadata about the target databases that RMAN uses for backup, recovery, and maintenance. RMAN always stores its metadata in the control file. The version of this metadata in the control file is the authoritative record of RMAN backups of your database. This is one reason why protecting your control file is an important part of your backup strategy. RMAN can conduct all necessary backup and recovery operations using just the control file to store the RMAN repository information, and maintains all records necessary to meet your configured retention policy.

You can also create a recovery catalog, which is a repository of RMAN metadata stored in an Oracle database schema. The control file has finite space for records of backup activities, whereas a recovery catalog can store a much longer history. You can simplify backup and recovery administration by creating a single recovery catalog that contains the RMAN metadata for all of your databases.

The owner of a recovery catalog can grant or revoke restricted access to the catalog to other database users. Each restricted user has full read/write access to his own metadata, which is called a virtual private catalog. When one or more virtual private catalogs exist in a database, the database contains just one set of catalog tables. These tables are owned by the base recovery catalog owner. The owner of the base recovery catalog controls which databases each virtual private catalog user can access.

Some RMAN features only function when you use a recovery catalog. For example, you can create a stored script in the recovery catalog and use this script to execute RMAN jobs. Other RMAN commands are specifically related to managing the recovery catalog and so are not available (and not needed) if RMAN is not connected to a recovery catalog.

The recovery catalog is maintained solely by RMAN. A target database instance never accesses the catalog directly. RMAN propagates information about the database structure, archived redo logs, backup sets, and datafile copies into the recovery catalog from the target database control file after any operation that updates the repository, and also before certain operations.

Media Management

The Oracle Media Management Layer (MML) API lets third-party vendors build a media manager, software that works with RMAN and the vendor's hardware to allow backups to sequential media devices such as tape drives. A media manager handles loading, unloading, and labeling of sequential media such as tapes. You must install media manager software to use RMAN with sequential media devices.

When backing up or restoring, the RMAN client connects to a target database instance and directs the instance to send requests to its media manager. No direct communication occurs between the RMAN client and the media manager.

RMAN Interaction with a Media Manager

Before performing backup or restore to a media manager, you must allocate one or more channels to handle the communication with the media manager. You can also configure default channels for the media manager. The default channels are used for all backup and recovery tasks that employ the media manager and for which you have not explicitly allocated channels.

RMAN does not issue specific commands to load, label, or unload tapes. When backing up, RMAN gives the media manager a stream of bytes and associates a unique name with this stream. When RMAN must restore the backup, it asks the media manager to retrieve the byte stream. All details of how and where that stream is stored are handled entirely by the media manager. For example, the media manager labels and keeps track of the tape and names of files on each tape, and automatically loads and unloads tapes, or signals an operator to do so.

Some media managers support proxy copy functionality, in which they handle the entire data movement between datafiles and the backup devices. These products may use technologies such as high-speed connections between storage and media subsystems to reduce the load on the primary database server. RMAN provides a list of files requiring backup or restore to the media manager, which in turn makes all decisions regarding how and when to move the data.

Oracle Secure Backup

Oracle Secure Backup is a media manager that provides reliable and secure data protection through file system backup to tape. All major tape drives and tape libraries in SAN, Gigabit Ethernet, and SCSI environments are supported.

Although Oracle Secure Backup has no specialized knowledge of database backup and recovery algorithms, it can serve as a media management layer for RMAN through the SBT interface. In this capacity, Oracle Secure Backup provides the same services for RMAN as other supported third-party SBT libraries. Oracle Secure Backup has some features, however, that are not available in other media managers.

See Also:

Oracle Secure Backup Administrator's Guide to learn how to use Oracle Secure Backup

Backup Solutions Program

The Oracle Backup Solutions Program (BSP), part of the Oracle PartnerNetwork, is a group of media manager vendors whose products are compliant with Oracle's MML specification. Several products may be available for your platform from media management vendors. For more information, contact your Oracle representative for a list of available products, contact individual vendors to ask them if they participate, or access the Backup Solutions Program Web site at:

http://www.oracle.com/technology/deploy/availability

Oracle does not certify media manager vendors for compatibility with RMAN. Questions about availability, version compatibility, and functionality can only be answered by the media manager vendor, not Oracle.

Fast Recovery Area

The components that create different backup and recovery-related files have no knowledge of each other or of the size of the file systems where they store their data. With automatic disk-based backup and recovery, you can create a fast recovery area (also called the recovery area), which automates management of backup-related files.

A fast recovery area minimizes the need to manually manage disk space for backup-related files and balance the use of space among the different types of files. In this way, a fast recovery area simplifies the ongoing administration of your database. Oracle recommends that you enable a recovery area to simplify backup management.

When you create a recovery area, you choose a location on disk and set an upper bound for storage space. You also set a backup retention policy that governs how long backup files are needed for recovery. The database manages the storage used for backups, archived redo logs, and other recovery-related files for the database within this space. Files no longer needed are eligible for deletion when RMAN must reclaim space for new files.

See Also:

"Configuring the Fast Recovery Area" to learn about the fast recovery area and how to configure it

RMAN in a Data Guard Environment

When using RMAN in a Data Guard environment, a recovery catalog is required. The recovery catalog can store the metadata for all primary and standby databases.

A database in a Data Guard environment is uniquely identified by means of the DB_UNIQUE_NAME parameter in the initialization parameter file. For RMAN to work correctly in a Data Guard environment, the DB_UNIQUE_NAME must be unique across all the databases with the same DBID.

See Also:

Oracle Data Guard Concepts and Administration to learn how to use RMAN in a Data Guard environment

RMAN Configuration in a Data Guard Environment

To simplify ongoing use of RMAN for backup and recovery, you can set a number of persistent configuration settings for each primary and physical standby database in a Data Guard environment. These settings control many aspects of RMAN behavior. For example, you can configure the backup retention policy, default destinations for backups to tape or disk, default backup device type, and so on.

You can use the CONFIGURE command with the FOR DB_UNIQUE_NAME clause to create a persistent configuration for a database in a Data Guard environment without connecting to the standby database or primary database as TARGET. For example, you connect RMAN to the recovery catalog, run the SET DBID command, and then can create a configuration for a physical standby database before its creation so that the RMAN configuration applies when the database is created.

RMAN updates the control file of the database when connected to it as TARGET during a recovery catalog resynchronization. If you use FOR DB_UNIQUE_NAME for a database without being connected as TARGET to this database, however, then RMAN changes configurations in the recovery catalog only.

RMAN File Management in a Data Guard Environment

RMAN uses a recovery catalog to track filenames for all database files in a Data Guard environment. The catalog also records where the online redo log files, standby redo log files, tempfiles, archived redo log files, backup sets, and image copies are created.

Interchangeability of Backups in a Data Guard Environment

RMAN commands use the recovery catalog metadata to function transparently across different physical databases in the Data Guard environment. For example, you can back up a tablespace on a physical standby database and restore and recover it on the primary database. Similarly, you can back up a tablespace on a primary database and restore and recover it on a physical standby database.

Note:

Backups of logical standby databases are not usable at the primary database.

Backups of standby control files and nonstandby control files are interchangeable. For example, you can restore a standby control file on a primary database and a primary control file on a physical standby database. This interchangeability means that you can offload control file backups to one database in a Data Guard environment. RMAN automatically updates the filenames for database files during restore and recovery at the databases.

Association of Backups in a Data Guard Environment

The recovery catalog tracks the files in the Data Guard environment by associating every database file or backup file with a DB_UNIQUE_NAME. The database that creates a file is associated with the file. For example, if RMAN backs up the database with the unique name of standby1, then standby1 is associated with this backup. A backup remains associated with the database that created it unless you use the CHANGE ...RESET DB_UNIQUE_NAME command to associate the backup with a different database.

Accessibility of Backups in a Data Guard Environment

The accessibility of a backup is different from its association. In a Data Guard environment, the recovery catalog considers disk backups as accessible only to the database with which they are associated, whereas tape backups created on one database are accessible to all databases. If a backup file is not associated with any database, then the row describing it in the recovery catalog view shows null for the SITE_KEY column. By default, RMAN associates a file whose SITE_KEY is null with the database to which they are connected as TARGET.

RMAN commands such as BACKUP, RESTORE, and CROSSCHECK work on any accessible backup. For example, for a RECOVER COPY operation, RMAN considers only image copies that are associated with the database as eligible to be recovered. RMAN considers the incremental backups on disk and tape as eligible to recover the image copies. In a database recovery, RMAN considers only the disk backups associated with the database and all files on tape as eligible to be restored.

To illustrate the differences in backup accessibility, assume that databases prod and standby1 reside on different hosts. RMAN backs up datafile 1 on prod to /prmhost/disk1/df1.dbf on the production host and also to tape. RMAN backs up datafile 1 on standby1 to /sbyhost/disk2/df1.dbf on the standby host and also to tape. If RMAN is connected to database prod, then you cannot use RMAN commands to perform operations with the /sbyhost/disk2/df1.dbf backup located on the standby host. However, RMAN does consider the tape backup made on standby1 as eligible to be restored.

Note:

You can transfer a backup from a standby host to a primary host or vice versa, connect as TARGET to the database on this host, and then use the CATALOG command to catalog the backup. After a file is cataloged by the target database, the file is associated with the target database.

See Also:

'ORACLE' 카테고리의 다른 글

Oracle ADG AFFIRM/NOAFFIRM VS SYNC/ASYNC  (0) 2021.12.21
Oracle sequence cache  (0) 2021.12.21
ORACLE ATP DB 접속  (0) 2020.01.27
Oracle ATP DB 생성  (0) 2020.01.27
sql  (0) 2019.12.23

1. 증상 및 원인

pip를 이용하여 원하는 패키지를 설치하려고 하면, 아래와 같은 에러가 발생할 수 있다. 주로 인트라넷을 사용하는 경우 아래와 같은 문제가 많이 발생한다. 아래와 같은 에러가 발생하는 이유는 각 회사 컴퓨터에는 신뢰할 수 있는 루트 인증 기관을 가지고 있게 되는데, 인증 기관으로 python을 설치하기 위한 도메인을 포함하지 않은 경우에 이런 에러가 발생할 수 있다.

 

2. 간단한 해결 방법

아래와 같은 명령어를 입력하여 문제를 해결할 수 있다.

$ pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org 설치할패키지이름
or
$ python3 -m pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org 설치할패키지이름

 

3. 영구적인 해결 방법

 

3.1. 인증된 Host 등록하기

위의 명령어는 pip나 python을 실행할 때마다 입력해야 하기 때문에, 아래와 같은 방법으로 영구적으로 해결할 수 있다.

$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools

 

3.2. self.verify = False 설정

SSL 인증서를 확인하지 않으려면 sessions.py 파일에 self.verify=False 를 설정한다.

(파일위치는 각자의 설치 경로를 확인한다.)

파일위치

C:\Users\{사용자명}\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\pip\_vendor\requests\sessions.py

 

해당파일을 열고, 

 

#: SSL Verification default.

self.verify = False  로 변경한다.

 

.

 

 

'Python' 카테고리의 다른 글

Python __main__ 이란  (0) 2021.12.30
Introduction to Python  (0) 2021.12.28
NAVER 자동 로그인  (0) 2021.12.14
Python 자동 로그인  (0) 2021.12.13
Visual Studio Code에 Python 설정하기  (0) 2021.12.12

basic task(기본 작업 만들기) vs task(작업 만들기)

 

 

'이것저것' 카테고리의 다른 글

스택(Stack)과 힙(Heap) 차이점  (0) 2022.01.02
전처리기  (0) 2021.12.31
apt vs apt-get 차이  (2) 2021.12.28
cron(UNIX/Linux) - 작업 예약 명령 - 수정  (0) 2021.12.14
crontab(Unix/Linux) 실행 시 환경변수  (0) 2021.12.14

Python Selenium으로 naver 자동 로그인 시 자동입력방지 프로그램이 작동하여 자동 로그인을 차단한다.

 

[ NAVER 자동로그인 코드]

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time 

options = Options()
options.add_experimental_option('excludeSwitches', ['enable-logging'])

def set_chrome_driver():
    chrome_options = webdriver.ChromeOptions()
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
    return driver

 

driver = set_chrome_driver()
driver.maximize_window()

driver.get("https://nid.naver.com/nidlogin.login")

 

## id/pass 입력
naver_id = driver.find_element(By.NAME, "id")
naver_id.send_keys('naver_id')
naver_password = driver.find_element(By.NAME, "pw")
naver_password.send_keys('naver_password')

 

## login 버튼클릭
driver.find_element(By.XPATH, '//*[@id="log.login"]').click()

 

위 코드와 같은 자동 로그인을 시도하면 아래와 같이 자동입력방지 프로그램이 작동한다.

자동입력 방지프로그램이 작동하지 않는 사이트는 위 코드를 활용해 자동 로그인 할 수 있다.

 

CentOS 6.4에서는 RHEL6 버전부터 사용된 anacron이 채용되어 있습니다.

이로 인해 RHEL5 버전까지 crontab에 설정되어 있던 run-part부분, 즉 /etc/cron.hourly/, /etc/cron.daily/, /etc/cron.weekly/, /etc/cron.monthly/ 의 실행부분이 빠지게 됩니다.

자세한 내용은 anacron에서 확인하세요.

cron

리눅스에서는 일반적으로 cron 데몬이 주기적인 작업 실행을 처리한다. cron이 시작될 때부터 끝날 때까지 계속 실행되며 cron 설정 파일은 cron table을 줄여서 crontab이라 부른다.

 

특정한 시간 또는 특정 시간마다 어떤 작업을 자동으로 수행하고자 할 때 cron 명령어 사용

crontab은 cron 작업을 설정하는 파일

 

* * * * * command(s)
^ ^ ^ ^ ^
| | | | |     allowed values
| | | | |     -------
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Run a Cron Job Every 10 Minutes

To run a cron job every 10 minutes, add the following line in your crontab file:

*/10  * * * * command

 

/var/spool/cron/

 

 

Unix/Linux shell script를 cron으로 동작시킬때 .bashrc .bash_profile .profile 의 변수가 적용되지 않는다.

 

.profile .cshrc .bashrc .bash_profile 등의 초기화 파일은  login shell 또는 interactive shell에서만 실행되기 때문에

crontab 으로 수행 시 초기화파일에 정의한 환경변수는 적용되지 않는다.

아래 3가지 방법 중 하나로 적용하면 환경변수가 적용되어 crontab에 등록한 쉘이 정상 작동한다.

 

설정방법

 

1. shell script 안에 초기화파일을 수행하는 라인 추가

#!/bin/bash

 . ~/.bash_profile

 

2. 쉘 script의 첫 라인에 bash -login 옵션을 사용.  --login 옵션(-l과 동일)을 사용하면 초기화파일이 모두 수행된다.

#!/bin/bash --login

 

3. root 유저로 수행

root 유저의 cron에 등록하여 su 스위치를 -c 옵션과 같이 사용하면 초기화파일이 수행된다.

예)   0 0 * * * su - username -c /home/username/check.sh

 

 

[ 설치환경 ]

- Microsoft Windows 10 Pro(10.0.19041 N/A 빌드 19041)

- VSCode (1.57.1)

- Python 3.9.9

- selenium

- chrome browser (버전 96.0.4664.93)

- ChromeDriver 96.0.4664.45

 

1. 브라우저 자동화나 크롤링을 위한 selenium

 

selenium 이란

selenium은 웹사이트 테스트를 위한 도구로 브라우저 동작을 자동화할 수 있다. 셀레니움을 이용하는 웹크롤링 방식은  프로그래밍으로 브라우저 동작을 제어해서 마치 사람이 이용하는 것 같이 웹페이지를 요청하고 응답을 받아올 수 있다

 Selenium은 마우스, 키보드의 동작과 디스플레이에 바로 나타나는 html과의 상호작용할 수 있다.


chromedriver 다운로드

셀레니움을 사용하기 위해서는 크롬드라이버 다운로드가 필요하다. 우선 자신의 크롬 브라우저가 어떤 버전을 사용하는지 확인해야 한 후 크롬 브라우저 버전에 맞는 chromedriver를 다운로드한다. 

(Window version 은 chromedriver_win32.zip 이다)

https://chromedriver.chromium.org/downloads

 

ChromeDriver - WebDriver for Chrome - Downloads

Current Releases If you are using Chrome version 97, please download ChromeDriver 97.0.4692.36 If you are using Chrome version 96, please download ChromeDriver 96.0.4664.45 If you are using Chrome version 95, please download ChromeDriver 95.0.4638.69 For o

chromedriver.chromium.org

 

selenium 설치

VSCode 실행 창에서 하단의 TERMINAL 창에서 pip install selenimu 명령어를 실행한다.

 

2. 자동로그인 source(예시)

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

def set_chrome_driver():
    chrome_options = webdriver.ChromeOptions()
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
    return driver

driver = set_chrome_driver()

## id/pass 입력
elem = driver.find_element(By.NAME, "userId")
elem.send_keys("userid")
elem = driver.find_element(By.NAME, "password")
elem.send_keys("userpassword")

## login 버튼클릭
driver.find_element(By.XPATH, '//*[@id="loginTab"]/div[1]/div/div[1]/div[1]/div[2]/button').click()
 
 

위 소스에서 자신이 자동로그인 하고 싶은 사이트를 지정하고 ID/패스워드를 변경한다.
 
--> 자신이 자동로그인 하고 싶은 SITE로 변경
 
## id/pass 입력
elem = driver.find_element(By.NAME, "userid")
--> Site의 계정 element 명으로 변경한다.
elem.send_keys("userid")
--> 본인의 ID를 입력한다.
 
elem = driver.find_element(By.NAME, "password")
--> Site의 패스워드 element 명으로 변경한다.
elem.send_keys("userpassword")
--> 본인의 패스워드를 입력한다.

 

 

 

+ Recent posts