🖊️ Experience

AWS Ubuntu 깃헙 자동커밋!!

date
Jul 20, 2023
slug
AWS Ubuntu2
author
status
Public
tags
Daily
Blog
Open Source
Github
summary
AWS를 이용해서 깃허브 자동커밋 장치 만들기
type
Post
thumbnail
category
🖊️ Experience
updatedAt
May 23, 2024 03:52 AM
이걸 성공했다는 가정하에 진행되는 이야기다.
이걸 완벽히 설치하고 오길 바란다.

계기

notion image
야발이거 11시59분에 커밋 때렸는 데 올라가는 데 몇초 걸리는 거 땜에 빵꾸남
내가 이걸 만든이유는 바로 1일1커밋 때문이다. 개발자라면 한번쯤은 해봤던 하고 있는 1일 1커밋 근데 우리가 만약 어디 여행을 가거나 친구들과 놀다보면 그걸 까먹는 경우가 있다. 그리고 알더라도 컴터가 없어서 핸드폰으로 문제를 풀어서 올리거나 Readme.md를 수정하는 경우도 있었다. 그래서 이 장치를 만들게 되었다.

Ubuntu 실행하고 시작하기

이제부턴 걍 Ubuntu에 명령어만 복사해서 붙여넣으면 된다. 개쉽다. shell명령어와 크론탭을 이용할 것이다.

1. 우분투 실행하기

PuTTY 키고 Load해서 불러온다음 Ubuntu실행하자
notion image

2. 깃 설치

sudo apt-get install git git --version git config --global user.name "Jamkris" git config --global user.email "dltmdgus1412@gmail.com"
notion image

3. SSH Key 생성

ssh-keygen -t rsa -C "dltmdgus1412@gmail.com" 엔터 3번 땅땅땅 cd /home/ubuntu/.ssh/ cat id_rsa.pub
notion image
ssh-rsa AAAAB ~~~ 부터 색칠한거 복사해두기

4. GitHub에 SSH Key 등록하기

notion image
notion image
Setting > SSH and GPG keys > New SSH Key
notion image
요딴식으로 붙여넣고 Add SSH Key 클릭
notion image

5. 깃헙 Repository 생성 및 git clone

notion image
이름 GitHubAutoCommit으로 지어라 Create repository
notion image
SSH로 바꾸고 깃헙주소 복사
cd .. git clone git@github.com:Jamkris/GitHubAutoCommit.git yes ls로 잘생성되었는 지 확인
notion image
지금부터 파일 어디에 생성하는 지 잘확인하면서 따라오길 바란다. 여기부터 좀 빡세다.

6. 스케줄링 SSH 파일생성

ls 이건 주기적으로 확인하면서 하자 plz mkdir git-sch ls cd git-sch vi git-sch.sh
notion image
하면 아마 밑에처럼 뜰거다.
notion image
Y=$(date +%Y) M=$(date +%m) D=$(date +%d) Ym=$Y-$M Ymd=$Y-$M-$D GitRep="GitHubAutoCommit" HomeDir="/home/ubuntu" GitDir="$HomeDir/$GitRep" FileDir="$HomeDir/$GitRep/$Ymd" FileNm="$Ymd".md mkdir -p $FileDir echo "### $Ymd 깃허브 자동커밋" >> $FileDir/$FileNm cd $GitDir git add . git commit -m "AutoCommit $FileNm" git push origin master
notion image
요따구로 붙여넣기하자
편집기 나오는 법
:wq 입력 후 {Enter}
notion image
SSH파일 권한주기
ls chmod +x git-sch.sh
notion image
notion image

7. 쉘 파일 실행하기

ls ./git-sch.sh
notion image
요로코롬 푸쉬가 잘 된다.

8. 날짜 설정하기

ls cd .. date
notion image
날짜가 우리나라 날짜가 아니다. 날짜를 설정해주자
ls cd /usr/share/zoneinfo/ ls sudo ln -sf /usr/share/zoneinfo/Japan /etc/localtime date
notion image
이제 크론탭을 재시작 해주자
cd /home/ubuntu ls sudo service cron restart sudo /etc/init.d/crond restart 이때 초기비밀번호는 ubuntu이다.
notion image

9. 크론탭 스케쥴링 테스트 하기

크론탭 리스트 확인 crontab -l 크론탭 등록 및 수정 crontab -e 여기서 1번 선택 후 {Enter}
notion image
그럼 이 창이 뜰텐데 여기에
* * * * * echo "cron works" >> /home/ubuntu/test.txt 이걸 써주고 Ctrl + X y Enter
notion image
notion image
cat /home/ubuntu/test.txt
notion image

10. 크론탭 스케쥴링 걸기

테스트용 크론탭 삭제
crontab -r
시간설정
crontab -e 35 21 * * * /home/ubuntu/git-sch/git-sch.sh 35는 분 21은 시간 알아서 설정하기
notion image
Ctrl + X y Enter 로 빠져나오기
하면 끝이다. 자동커밋 완스엉
notion image
notion image

모르는 거나 오류났다면

Insta : hyun_2u
Email : dltmdgus1412@gmail.com
KaKaoTalk : hyun_2u
댓글 ㅆㄱㄴ

유익했다면 개추