我正在尝试在 shell 脚本中使用以下命令..有什么建议可以正确地执行此操作吗?
[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 -