I have created a simple executable script to move a file for me, as the name of the file is the date on each day, the script creates the file name and then moves the file. I want to schedule it to run every night using cron.
My script works when I run it in bash. It also works if I specify exactly the path and filename in the cron.
The problem occurs when I ask cron to run my script. It seems to me cron cannot run the subprocess to create the filename based on the date. my script is as follow:
#!/bin/bash
mv /home/folder1/$(date "+%Y-%m-%d").txt /media/folder2/folder3
and this is how I set the job in crontab:
0 21 * * * /home/folder1/bash_text.txt
I have tried with $(which mv), with no luck. (tried both in the script and cron command)
0 21 * * * $(which mv) /home/folder1/$(date "+%Y-%m-%d").txt /media/folder2/folder3
This only worked if I substituted the name of the file $(date "+%Y-%m-%d").txt with the actual file name.
0 21 * * * $(which mv) /home/folder1/2020-04-28.txt /media/folder2/folder3
Appreciate it if someone can help me, please. I am new to Linux as you can tell, so I am learning as I go, appreciate if you consider this in your replies.
date
inside of a cron tab job? – Kusalananda Apr 28 '20 at 11:48