crontab에서 "%" 사용하기

crontab에서 "%" 사용하기

원격 서버에서 내 (Ubuntu12) 로컬 컴퓨터로 rsync를 수행하고 로그 파일을 생성하기 위해 cron 작업을 추가하려고 합니다.

아래는crontab-l

00 18 * * * rsync -a -v --delete -e ssh user@centosvm:/home/user/rsync-test ~/backup > ~/rsync$(date +%Y%m%d_%H%M%S).log 2>&1

내 작업에 문법 오류가 있다는 이메일이 계속 옵니다.

Received: by work-virtual-machine (Postfix, from userid 1002)

        id 697ADA24A0; Thu, 30 Apr 2015 16:21:01 -0700 (PDT)

From: root@work-virtual-machine (Cron Daemon)

To: user@work-virtual-machine

Subject: Cron <user@work-virtual-machine> "rsync -a -v --delete -e ssh user@centosvm:/home/user/rsync-test ~/backup > /home/user/rsync$(date +

Content-Type: text/plain; charset=ANSI_X3.4-1968

X-Cron-Env: <SHELL=/bin/sh>

X-Cron-Env: <HOME=/home/user>

X-Cron-Env: <PATH=/usr/bin:/bin>

X-Cron-Env: <LOGNAME=user>

Message-Id: <20150430232101.697ADA24A0@work-virtual-machine>

Date: Thu, 30 Apr 2015 16:21:01 -0700 (PDT)

/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

unix2dos 패키지도 설치했습니다.

답변1

알았어 – 알아냈어. 누군가가 어느 시점에서 이 내용을 발견할 경우를 대비하여 이 내용을 다시 게시합니다. The % sign has a special meaning in crontab. it's changed to newline and any string after the first % will be sent to the command as standard input. To force cron to interpret it literally, you have to escape it:

00 18 * * * rsync -a -v --delete -e ssh user@centosvm:/home/user/rsync-test ~/backup > ~/rsync$(date +\%Y\%m\%d_\%H\%M\%S).log 2>&1

관련 정보