ルートとして他のユーザーのcrontabにアイテムを作成するにはどうすればよいですか?

ルートとして他のユーザーのcrontabにアイテムを作成するにはどうすればよいですか?

シェルスクリプトで次のコマンドを使用しようとしています。これを正しく実行する方法に関する提案はありますか?

[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

おすすめ記事