1

I've read the answers to this question, but still don't understand what to do:

How to use my aliases in my crontab?

I am logged onto my Ubuntu server as root. I have the following command in my .profile:

alias test-alias="echo test"

I have the following command in my crontab file:

11 9 * * *      source /root/.profile; test-alias > /root/tmp.output 2>&1

When this command runs, the only output present in tmp.output is:

/bin/sh: 1: test-alias: not found

What am I doing wrong here? How can I use my test-alias in my crontab file? I want to use the alias directly in the command, I don't want to create additional scripts to run the alias.

1 Answers1

1

Although it's not the prettiest solution and although I would suggest you against using it, what you can do is:

11 9 * * *      bash -ic "test-alias > /root/tmp.output 2>&1"

This will run bash as interactive shell (-i) and will thus read bashrc. To make sure .profile is sourced, you need to have this block in your .bashrc:

[ -f ~/.profile ] && source ~/.profile

Note that this kind of running cron jobs or writing scripts is a really bad practice, and you should try and avoid it.

Jakov Sosic
  • 5,407