Cron – How to use the aliases in the crontab

aliascronshell

I have some commands in my .profile that I want to invoke from my crontab.

For example, if I have,

alias notify-me="~/bin/notify.pl -u user1"
alias notify-team="~/bin/notify.pl -u user1 user2 user3 user4 ...."

I'd like to just invoke the alias

0 11 * * * notify-team

so if the list in my .profile is updated, I don't have to update the crontab, too. However, I don't seem to be able to use aliases in my crontab. Is there a work around?

I tried the suggestions here to set up the environment (e.g. /bin/bash -lc and the script-wrapper script). It seems like that works for scripts but not aliases.

Any ideas?

Best Answer

From the manpage regarding aliases:

Note aliases are not expanded by default in  non-interactive  shell,
and  it  can  be  enabled  by  setting  the 'expand_aliases'
shell option using shopt.

So try using shopt -s expand_aliases at the start of your sourcing script. This should let you use Warner's suggestion.