Can I say:
0 1 * * * $MYPATH/$MYSCRIPT
in crontab -e ?
Is it possible to use variables in crontab -e ?
Yes, you can define and use variables in this way. There's a limitation (which you haven't hit in your examples): the string on the right of the
This is stated in the documentation, which you can see by running
While Linux crontabs support defining some variables that hold literal values, it isn't much use besides condensing long text to a shorter representation or controlling some things about cron itself, such as where to send email output.
The flexibility is understanding that the command part of the cron entry will be passed to
For example, I have a simple crontab line that archives an MBX file of saved messages monthly and compresses it. It looks like this:
This will run the first of each month at 12:15 AM, set a new file name with CCYYMM in it, move current file to new name and compress it. The thing to remember is an unescaped
Just made a try, yes it's possible. You can figure it out with this simple example, put this in your
FOO=qwerty * * * * * echo $FOO > ~/out
And check the file
No you can't a cronjob can only contain cron items. Is it not an option to create a bash-script and run the bash-script via a cronjob?