Background
The PNG image files I want to use is stored in directories according to date, for example:
/NAS-mein/data/201812/
PNG stored within it like /NAS-mein/data/201812/foo/bar/20181231_1500.png
So I created a symbolic link PNG_path
in my home directory
ln -s /NAS-mein/data/201812/ PNG_path
and I'm able to update it manually through:
ln -sf /NAS-mein/data/201812/ PNG_path
which works fine and returns `PNG_path' -> `/NAS-mein/data/201812'
I'm in a CentOS 6.7 environment and I don't have superuser privilege.
The destination directory is created by the others but granted 777 permission, i.e.:
drwxrwxrwx /NAS-mein/
drwxrwxrwx /NAS-mein/data/
drwxrwxrwx /NAS-mein/data/201812/
With Crontab
Then I tried to automatically update this symbolic link on the first day of month, so it will always redirect me to the directory of current date.
I tried start a job in crontab like:
0 0 1 * * ln -sf /NAS-mein/data/$(date "+%Y%m") /home/me/PNG_path >>/home/me/.pngln.log 2>>&1
but this does not work, even without giving any information to the log.
So I tried:
0 0 1 * * cd /home/me/ && ln -sf /NAS-mein/data/$(date "+%Y%m") PNG_path >>.pngln.log 2>>&1
and wrap it into a Bash script like:
#!/bin/bash
/bin/unlink "/home/me/PNG_path"
/bin/ln -sf /NAS-mein/data/$(date "+%Y%m") PNG_path >>/home/me/.pngln.log 2>>&1
but all of above seem not working as the symbolic link does not change,
and no any information was logged (i.e. .pngln.log
is not created anyway.)
I'm not sure where I did it wrong, or using ln
in crontab
is just not a legit use?
Edit: I notice that I didn't write the most suspicious part: using date function in ln
expression.