๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • Welcome.
:: Linux ๐Ÿšฉ/Linux_basic

[๋ฆฌ๋ˆ…์Šค] [at , cron]

by EunBird 2021. 5. 18.

#1. at

 

# ntp ์„œ๋ฒ„ ์ค‘์ง€
systemctl stop ntpd

systemctl stop chronyd  

yum -y install at

# at ์‹คํ–‰
/usr/sbin/atd

# at ์‹คํ–‰ 2
systemctl restart atd

# at ์„œ๋น„์Šค ํ™•์ธ
ps -ef | at

# ์˜ˆ์•ฝ์ž‘์—… ํ™•์ธ
at -l

# ์˜ˆ์•ฝ์ž‘์—… ํ™•์ธ 2
atq

 

# ์‹œ๊ฐ„ ๋ณ€๊ฒฝ
date -s '2021-05-16 14:10'

# at HH:mm MMddyyyy
at 14:11 05162021
#> touch /tmp/at
#> [ Ctrl + D ] ๋กœ ๋น ์ ธ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.


# job ํ™•์ธ
at -l

# job ์‚ญ์ œ
at -d [job ๋ฒˆํ˜ธ]

 

 

 


watch -n 1 ls -ld /tmp/at


echo "touch /tmp/at" | at 14:11 05162021

vim tmp.sh
###############################
#!/bin/bash

touch /tmp/at
###############################

# ์˜ˆ์•ฝ๋œ ์‹œ๊ฐ„์— ์‰˜ ํŒŒ์ผ ์‹คํ–‰
at 14:11 05162021 -f tmp.sh

# ์˜ˆ์•ฝ๋œ ์‹œ๊ฐ„์— ์‰˜ ํŒŒ์ผ ์‹คํ–‰ 2
at 14:11 05162021 < tmp.sh

 

 

 

 


#2. cron

 

# crontab package ์„ค์น˜
yum -y install cronie

# cron ์‹คํ–‰ 1
/usr/sbin/crond

# cron ์‹คํ–‰ 2
systemctl start crond

# ์˜ˆ์•ฝ ์ž‘์—… ํ™•์ธ
crontab -l


#  2. 1๋ฒˆ์—์„œ ์ž‘์„ฑํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ์ด์šฉํ•˜์—ฌ ๋งค ๋ถ„๋งˆ๋‹ค /tmpํด๋”์— ์žˆ๋Š”
#     ํŒŒ์ผ์„ ์ž๋™์œผ๋กœ ์ •๋ฆฌํ•˜๋„๋ก ํ•˜์‹œ์˜ค.

# ์˜ˆ์•ฝ ์ž‘์—… ์ถ”๊ฐ€
# *ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€*ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€*ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€*ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€*
# ๋ถ„(0-59)ใ€€ใ€€์‹œ๊ฐ„(0-23)ใ€€ใ€€์ผ(1-31)ใ€€ใ€€์›”(1-12)ใ€€ใ€€ใ€€์š”์ผ(0-7) ์›” - ์ผ
==================================================
crontab -e
==================================================
* * * * * /app/script/shell/fileArrange.sh /tmp
==================================================

# ๋งค์ฃผ ๊ธˆ์š”์ผ ์˜ค์ „ 5์‹œ 45๋ถ„์— fileArrange.sh ๋ฅผ ์‹คํ–‰
45 5 * * 5 /app/script/shell/fileArrange.sh /tmp

# ๋งค์ผ ๋งค์‹œ๊ฐ„ 0๋ถ„, 20๋ถ„, 40๋ถ„์— fileArrange.sh ๋ฅผ ์‹คํ–‰
0,20,40 * * * * /app/script/shell/fileArrange.sh /tmp

# ๋งค์ผ 1์‹œ 0๋ถ„๋ถ€ํ„ฐ 30๋ถ„๊นŒ์ง€ ๋งค๋ถ„ fileArrange.sh ๋ฅผ ์‹คํ–‰
0-30 1 * * * /app/script/shell/fileArrange.sh /tmp

# ๋งค 10๋ถ„๋งˆ๋‹ค fileArrange.sh ๋ฅผ ์‹คํ–‰
*/10 * * * * /app/script/shell/fileArrange.sh /tmp

# 5์ผ์—์„œ 6์ผ๊นŒ์ง€ 2์‹œ,3์‹œ,4์‹œ์— ๋งค 10๋ถ„๋งˆ๋‹ค fileArrange.sh
 ๋ฅผ ์‹คํ–‰
*/10 2,3,4 5-6 * * /app/script/shell/fileArrange.sh /tmp

# ํฌ๋ก ํƒญ ๋ฐฑ์—…
crontab -l > /tmp/cron_config.bak

CRON

 

 


mkdir -p /app/script/shell/
--1๋ฒˆ ํŒŒ์ผ--
#  1. ์‹คํ–‰ ํ”„๋กœ๊ทธ๋žจ์„ ์ œ์™ธํ•œ ๋ชจ๋“  ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ ๋‚ ์งœ์— ๋งž๋Š” 
#     ํด๋”๋กœ ์ด๋™ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.
#     ํŒŒ๋ผ๋ฉ”ํ„ฐ๋กœ ์ž‘์—…ํ•  ํด๋”๋ฅผ ์ง€์ •ํ• ์ˆ˜ ์žˆ๋„๋ก ํ•˜์‹œ์˜ค. (์—†์„ ๊ฒฝ์šฐ ํ˜„์žฌ ํด๋” ์ž‘์—…)
:<<'END'
==================================================
fileArrange.sh
==================================================
#!/bin/bash                                                                                         
                                                                                                    
param1=$1                                                                                           
                                                                                                    
if [ -d $1 ] && [ -n "$1" ]                                                                         
then                                                                                                
        parent=$(dirname "${param1}")                                                               
                                                                                                    
        if [ "$parent" == "/" ]                                                                     
        then                                                                                        
                unset parent                                                                        
        fi                                                                                          
                                                                                                    
        param1=${parent}/$(basename "${param1}")/                                                   
else                                                                                                
        param1='./'                                                                                 
fi

ls -l $param1 --time-style="+%Y%m%d" | grep -v total | awk '{print $6 " " $7}' | while read result  
do                                                                                                  
        date=`echo $result | awk '{print $1}'`                                                      
        fname=`echo $result | awk '{print $2}'`                                                     
                                                                                                    
        if [ "${0##*/}" == "${fname}" ]                                                             
        then                                                                                        
                continue                                                                            
        fi                                                                                          
                                                                                                    
        if [ -d $param1$fname ]                                                                     
        then                                                                                        
                continue                                                                            
        fi                                                                                          
                                                                                                    
        if [ ! -d $date ]                                                                           
        then                                                                                        
                mkdir -p $param1$date                                                               
        fi                                                                                          
                                                                                                    
        mv $param1$fname $param1$date/                                                              
done   

728x90

๋Œ“๊ธ€