![루트로서 다른 사용자의 crontab에 항목을 어떻게 생성합니까?](https://linux55.com/image/193930/%EB%A3%A8%ED%8A%B8%EB%A1%9C%EC%84%9C%20%EB%8B%A4%EB%A5%B8%20%EC%82%AC%EC%9A%A9%EC%9E%90%EC%9D%98%20crontab%EC%97%90%20%ED%95%AD%EB%AA%A9%EC%9D%84%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EC%83%9D%EC%84%B1%ED%95%A9%EB%8B%88%EA%B9%8C%3F.png)
쉘 스크립트에서 다음 명령을 사용하려고 합니다. 이 작업을 올바르게 수행하는 방법에 대한 제안 사항이 있습니까?
[root@testserver ~]# crontab -u oracle -e >> 0 0 * * * /usr/local/scrips/setup.sh
crontab: usage error: no arguments permitted after this option
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u <user> define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
-n <host> set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-s selinux context
-x <mask> enable debugging
Default operation is replace, per 1003.2
답변1
이 -e
스위치는 crontab을 대화형으로 만들지만 이는 바람직하지 않은 동작입니다.
구문을 사용하는 것이 좋습니다 crontab -u user file
. 아래는 예입니다:
root@c:~# crontab -l -u user
no crontab for user
root@c:~# echo "10 10 * * * /bin/true" >> to_install
root@c:~# crontab -u user to_install
root@c:~# crontab -l -u user
10 10 * * * /bin/true
root@c:~# crontab -l -u user > temp
root@c:~# echo "12 12 * * * /bin/false" >> temp
root@c:~# crontab -u user temp
root@c:~# crontab -l -u user
10 10 * * * /bin/true
12 12 * * * /bin/false
답변2
또는 한 줄로:
(sudo crontab -u user -l ; echo "*/5 * * * * /folder/script.sh") | sudo crontab -u user -