Various examples and tips for using the watch command in Linux

What is the Linux watch command? The Linux watch command is a useful tool that repeatedly displays the result of a specific command at regular intervals. For example, you can use it to monitor the system’s CPU and memory usage, detect changes in files, or check the network connection status. The basic format of the watch command is as follows. 1 watch [options] [command] cs There are various options, but the most commonly used ones are as follows. -n : Specifies the update interval in seconds. The default value is 2 seconds. -d : Highlights the parts that have changed compared to the previous result. -t : Does not display the time at the top. -c : Keeps the color. Examples of using the watch command Let’s look at some examples of how to use the watch command. 1. Monitoring system CPU and memory usage If you want to monitor the system’s CPU and memory usage, you can use the watch command with the top command. For example, if you enter the following, it will update the result of the top

리눅스에서 watch 명령어를 활용하는 다양한 예제와 팁

리눅스 watch 명령어란? 리눅스 watch 명령어는 특정 명령어의 결과를 주기적으로 반복해서 출력해주는 유용한 도구입니다. 예를 들어, 시스템의 CPU 사용량이나 메모리 사용량을 모니터링하거나, 파일의 변화를 감지하거나, 네트워크 연결 상태를 확인하는 등의 작업을 할 때 사용할 수 있습니다. watch 명령어의 기본 형식은 다음과 같습니다. 1 watch [옵션] [명령어] cs 옵션에는 다양한 것들이 있지만, 가장 자주 사용되는 것은 다음과 같습니다. -n : 갱신 주기를 초 단위로 지정합니다. 기본값은 2초입니다. -d : 이전 결과와 비교하여 변화된 부분을 강조합니다. -t : 상단에 시간을 표시하지 않습니다. -c : 색상을 유지합니다. watch 명령어의 사용 예제 watch 명령어를 사용하는 방법에 대해 몇 가지 예제를 보겠습니다. 1. 시스템의 CPU 사용량과 메모리 사용량 모니터링하기 시스템의 CPU 사용량과 메모리 사용량을 모니터링하고 싶다면, top 명령어와 함께 watch 명령어를 사용할 수 있습니다. 예를 들어, 다음과 같이 입력하면 1초마다 top 명령어의 결과를 갱신하고, 변화된 부분을 강조합니다. 1 watch -n 1 -d top cs 2. 파일의 변화 감지하기 파일의 변화를 감지하고 싶다면, ls 명령어와 함께 watch 명령어를 사용할 수 있습니다. 예를 들어, 다음과 같이 입력하면 5초마다 현재 디렉토리의 파일들을 출력하고, 변화된 부분을 강조합니다. 1 watch -n 5 -d ls cs 3. 네트워크 연결 상태 확인하기 네트워크 연결 상태를 확인하고 싶다면, ping 명령어와 함께 watch 명령어를 사용할 수 있습니다. 예를 들어, 다음과 같이 입력하면 10초마다 특정 도메인에 대한 ping 결과를 출력하고, 변화된 부분을 강조합니다. 1 watch -n 10 -d ping www.google.com cs 결론 리눅스 watch 명령어는 특정 명령어의 결과를 주기적으로 반복해서 출력해주는 유용한 도구입니다. 시스템의

How to set up crontab and check if it works

What is crontab? crontab is a command that allows you to schedule periodic tasks on Linux. For example, you can use crontab to automate tasks such as backing up every night, deleting logs every Monday, or checking system status every hour. crontab can be divided into two types: System-wide crontab: Tasks defined in the /etc/crontab file that are shared by all users. Individual user’s crontab: Tasks that each user creates and manages with the crontab command that only the user can access. In this post, we will learn about the individual user’s crontab and how to set it up and check if it works. How to set up crontab The crontab command has the following options: -e: Edit the crontab file. By default, the vi editor opens, but you can use a different editor by setting the EDITOR environment variable. -l: Print the contents of the current crontab file. -r: Delete the current crontab file. To edit the crontab file, enter the following command: 1 $ crontab -e cs Then you can define tasks in

crontab 설정방법과 로그 확인하는 법

crontab이란? crontab은 리눅스에서 주기적으로 특정 작업을 수행하도록 예약하는 명령어입니다. 예를 들어, 매일 밤 백업을 하거나, 매주 월요일에 로그를 삭제하거나, 매시간마다 시스템 상태를 체크하는 등의 작업을 crontab을 이용하여 자동화할 수 있습니다. crontab은 크게 두 가지로 구분할 수 있습니다. 시스템 전체의 crontab : /etc/crontab 파일에 정의된 작업들로, 모든 사용자가 공유합니다. 개별 사용자의 crontab : 각 사용자가 crontab 명령어로 생성하고 관리하는 작업들로, 해당 사용자만이 접근할 수 있습니다. 이번 포스팅에서는 개별 사용자의 crontab에 대해 알아보고, 설정방법과 성공여부 확인 방법에 대해 설명하겠습니다. crontab 설정방법 crontab 명령어는 다음과 같은 옵션을 가집니다. -e : crontab 파일을 편집합니다. 기본적으로 vi 에디터가 열리지만, EDITOR 환경변수를 설정하여 다른 에디터를 사용할 수 있습니다. -l : 현재 설정된 crontab 파일의 내용을 출력합니다. -r : 현재 설정된 crontab 파일을 삭제합니다. crontab 파일을 편집하려면 다음과 같이 명령어를 입력합니다. 1 $ crontab -e cs 그러면 다음과 같은 형식으로 작업을 정의할 수 있습니다. 1 분 시 일 월 요일 명령어 cs 각 항목은 다음과 같은 의미를 가집니다. 분 : 0 ~ 59 사이의 숫자로, 명령어가 실행될 분을 지정합니다. 시 : 0 ~ 23 사이의 숫자로, 명령어가 실행될 시간을 지정합니다. 일 : 1 ~ 31 사이의 숫자로, 명령어가 실행될 날짜를 지정합니다. 월 : 1 ~ 12 사이의 숫자로, 명령어가 실행될 달을 지정합니다. 요일 : 0 ~ 6 사이의 숫자로, 명령어가 실행될 요일을 지정합니다. 0은 일요일, 1은 월요일 … 6은 토요일입니다. 명령어 : 실행할 쉘 스크립트나 프로그램의 경로와 옵션입니다. 예를 들어, 매일 오전 10시에 /home/user/backup.

A Simple Way to Use the FTP Module in PHP

A Simple Way to Use the FTP Module in PHP PHP is a widely used scripting language for web development. With PHP, you can create dynamic web pages or interact with databases. However, to write and execute PHP code, you need to upload PHP files to the web server.  You can easily transfer PHP code to the remote server using the FTP (File Transfer Protocol) module. The FTP module is provided as a built-in function in PHP and offers various features for connecting and transferring files to the FTP server. To use the FTP module, you need information such as the address, ID, password of the FTP server. Then you can call the functions of the FTP module to create a connection with the FTP server and upload or download files. In this post, we will briefly look at how to use the FTP module in PHP. Creating a connection with the FTP server. To use the FTP module, you need to create a connection with the FTP server first. To do this, use the ftp_connect() and ftp_login() functions. The ftp_connect(

PHP에서 FTP 모듈을 활용하는 간단한 방법

PHP에서 FTP 모듈을 활용하는 간단한 방법 PHP는 웹 개발에 널리 사용되는 스크립트 언어입니다. PHP를 사용하면 웹 페이지를 동적으로 생성하거나 데이터베이스와 연동할 수 있습니다. 하지만 PHP 코드를 작성하고 실행하기 위해서는 웹 서버에 PHP 파일을 업로드해야 합니다. 이때 FTP(File Transfer Protocol) 모듈을 사용하면 PHP 코드를 쉽게 원격 서버에 전송할 수 있습니다. FTP 모듈은 PHP의 내장 함수로 제공되며, FTP 서버와의 연결 및 파일 전송을 위한 다양한 기능을 제공합니다. FTP 모듈을 사용하려면 먼저 FTP 서버의 주소, 아이디, 비밀번호 등의 정보가 필요합니다. 그리고 FTP 모듈의 함수들을 호출하여 FTP 서버와의 연결을 생성하고, 파일을 업로드하거나 다운로드할 수 있습니다. 이번 포스팅에서는 PHP에서 FTP 모듈을 사용하는 방법에 대해 간단히 알아보겠습니다. FTP 서버와의 연결 생성 FTP 모듈을 사용하기 위해서는 먼저 FTP 서버와의 연결을 생성해야 합니다. 이를 위해 ftp_connect() 함수와 ftp_login() 함수를 사용합니다. ftp_connect() 함수는 FTP 서버의 주소와 포트 번호를 인자로 받아서 FTP 서버와의 연결을 생성하고, 연결 식별자를 반환합니다. 만약 연결에 실패하면 false를 반환합니다. ftp_login() 함수는 FTP 서버에 로그인하기 위해 연결 식별자, 아이디, 비밀번호를 인자로 받습니다. 만약 로그인에 성공하면 true를 반환하고, 실패하면 false를 반환합니다. 다음은 FTP 서버와의 연결을 생성하는 예제 코드입니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <?php // FTP 서버의 주소와 포트 번호 $server = "ftp.example.com"; $port = 21; // FTP 서버에 로그인하기 위한 아이디와 비밀번호 $user = 

로그 파일이 너무 많아요? ubuntu에서 logrotate로 로그 정리하기

logrotate란 무엇인가요? 로그 파일은 시스템이나 애플리케이션의 작동 상태를 기록하는 파일입니다. 로그 파일은 문제를 진단하거나 성능을 분석하는 데 유용하지만, 너무 많아지면 디스크 공간을 차지하고 관리하기 어려워집니다. logrotate는 이러한 문제를 해결하기 위해 만들어진 유틸리티입니다. logrotate는 로그 파일의 크기와 수명을 제어하고, 필요에 따라 압축하거나 삭제하거나 이메일로 전송하는 등의 작업을 자동으로 수행할 수 있습니다. logrotate는 주기적으로 cron에 의해 실행되며, /etc/logrotate.conf 파일과 /etc/logrotate.d 디렉토리에 있는 설정 파일들을 읽어서 로그 파일을 관리합니다. ubuntu에서 logrotate를 설치하고 설정하는 방법 ubuntu에서 logrotate는 기본적으로 설치되어 있습니다. 만약 설치되어 있지 않다면, 다음 명령어로 설치할 수 있습니다. 1 sudo apt - get install logrotate cs logrotate의 설정 파일은 /etc/logrotate.conf와 /etc/logrotate.d 디렉토리에 있습니다. /etc/logrotate.conf는 전역 설정을 담고 있으며, /etc/logrotate.d 디렉토리에는 각각의 로그 파일이나 그룹에 대한 설정을 담고 있는 파일들이 있습니다. logrotate의 설정 파일은 다음과 같은 형식으로 작성됩니다. 1 2 3 4 # 로그 파일이나 그룹의 경로 {   # 옵션들 } cs 옵션들은 다양한 기능을 제공하는데, 자주 사용되는 옵션들은 다음과 같습니다. size: 로그 파일의 크기가 지정된 값보다 커지면 로테이션을 수행합니다. 단위는 k, M, G 등으로 표시할 수 있습니다. rotate: 로그 파일을 몇 개까지 보관할 것인지 지정합니다. 예를 들어 rotate 5라고 하면, 최근 5개의 로그 파일만 남기고 나머지는 삭제합니다. daily: 매일 로테이션을 수행합니다. weekly, monthly 등도 사용할 수 있습