以下をテストしましたが、運がありませんでした。別のアイデアがありますか?
#cron test, I would like to generate a stderr logfile name based on $0, but $0 value is "/bin/bash"
#why do I want this? Because some program names are quite long, and for standardization
04 10 * * * ~/bin/cron-test >> /tmp/blah 2>>~/.cronlogs/$(basename $0) # $0 is "/bin/bash"
05 10 * * * ~/bin/cron-test >> /tmp/blah 2>>~/.cronlogs/$(basename $1) # $1 is empty?
06 10 * * * ~/bin/cron-test >> /tmp/blah 2>>~/.cronlogs/$(basename $2) # $2 is empty?
答え1
出力を特定の場所に送信するラッパースクリプトを作成できます。
$ cat logwrap.sh
#!/bin/bash
logname=$(basename -- "$1").log
exec "$@" 2>> "~/.cronlogs/$logname"
logwrap.sh id some command
実行は出力をsome command
に送信する/work/logs/some.log
ので、出力は次に送信されます。/work/logs/cron-test.log
04 10 * * * /path/to/logwrap.sh ~/bin/cron-test