crontab 문의드립니다

darkharf2의 이미지

안녕하세요 일전에 글 올렸었던 신입 회원입니다.

다름이 아니라 현재 우분투사용중이며 cron작업설정중인데 잘되지 않아서 어디가 문제인지 몰라서 다시 글올려봅니다.선배님들의 조언이 간절하ㅇ니

부디 외면하지 마시고 확인 한번만 부탁드립니다.

현재 제가 crontab -e사용하여 수정한 내용은 아래와 같습니다

GNU nano 2.2.6 파일: /tmp/crontab.sdSgKr/crontab

# Output of the crontab jobs (including errors) is sent through email to the us$
# the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts at 5 a.m every we$
# with: 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command

*/1 * * * * /home/tact2/cron_backup/db_mysql_backup1.sh

아래와 같이 설정하고 실행하려 하는데 crontab이 작동되지 제가 혹시 설정을 잘못한게 잇을까요

쉘스크립트만 따로 실행하였을 경우 쉘스크립트는 제대로 실행이 되면서 backup파일이 제대로 생성됩니다.

crontab에서 어느 부분을 수정 보완하여야 할지 선배님들 따뜻한 조언 부탁드립니다

#!/bin/bash
/usr/bin/mysqldump -uroot -proot --events --ignore-table=mysql.event --all-databases > /home/tact2/db_mysql_test_$(`date + %Y%m%d`).sql

dkTkfl@whgrnsk:/etc$ /etc/init.d/cron restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service cron restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop cron ; start cron. The restart(8) utility is also available.
stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.68" (uid=1000 pid=29916 comm="stop cron ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
~

그리고 restart할경우 지금 제대로 restart가 된건지도 문의드립니다...ㅠ
sudo service cron restart
[sudo] password for tact2:
cron stop/waiting
cron start/running, process 31180
tact2@tact2:~$
tact2@tact2:~$
tact2@tact2:~$ ps -ef | grep cron
root 31180 1 0 13:59 ? 00:00:00 cron
tact2 31182 30394 0 13:59 pts/6 00:00:00 grep --color=auto cron
tact2@tact2:~$

혹시 몰라 쉘스크립트의 내용도 첨부하오니 참조하여 주시기 바랍니다

눈이 내려 빙판길이 되어서 위험하네요 모두 조심하시고 오늘도 즐거운 하루 보내세요

감사합니다

peecky의 이미지

$(`date + %Y%m%d`) 부분을 $(`date +%Y%m%d`) 로 바꿔보세요. (플러스 다음에 공백 제거)

그래도 안 되면 cron의
*/1 * * * * /home/tact2/cron_backup/db_mysql_backup1.sh
부분을
*/1 * * * * /home/tact2/cron_backup/db_mysql_backup1.sh >> ~/crontab.log 2>&1
로 바꾸고 crontab.log 파일에 어떤 메시지가 찍히는지 살펴보세요.

darkharf2의 이미지

peecky님 답변 너무나 감사드립니다.

제가 이제 막 it시작하여 부족하여서다시 질문 여쭙니다

*/1 * * * * /home/tact2/cron_backup/db_mysql_backup1.sh >> ~/crontab.log 2>&1<<부분이 crontab에 넣었을경우 실행이 되는건가요..

제가 쉘스크립트만 돌렸을경우에는 파일이 생성이 되는데 crontab에 넣엇을 경우 파일이 생성되지 않아서.....

어떤분은 이런경우가 발생할경우 대부분 Path의 문제라고도 말슴해주셨는데..

Path는 어떻게 설정해야하는지 제가 잘 알지 못합니다 .ㅠ 아무래도 Path가 맞다고 짐작하는 이유는 제가 crontab -e 수정하고 나올경우 예전에는 crontab: installing new crontab문구가 없었는데

아래와 같이 할경우 crontab: installing new crontab 글이 뜨는게 cron이 적용이되는구나 이런 생각이 들더라구요

헌제 Path관련 조언 받은 부분은

path지정이 안될 경우

db 백업이니 db유저로 돌게끔 설정을 해보세요
아래는 예시입니다
# */1 * * * * su - oracle -c /home/tact2/cron_backup/db_mysql_backup1.sh 답변을 받았는데

위와 같습니다 헌제 제가 저기 -oracle -c에 어떻게 변경해서 넣어야할지 아직 적용을 못해봤습니다...ㅠ

만약 mysql사용한다면 su -mysql -[사용자 아이디] /home/tact2/cron_backup/db_mysql_backup1.sh 이렇게 적용하면될까요..ㅠ

안되니깐 너무 답답하네요...ㅠㅠ