I have this cronjob.
50 15 * * * cd /var/www/html; for i in $(ls -d */); do tar zcvf ${i%%/}.tar.gz $i; done
But it shows me this.
/bin/sh: 1: Syntax error: Missing '}'
But when I run this command from command line directly, it works.
Where is the problem?
Thanks.
for i in $(ls -d */)
- see for example Bash pitfall #1 – steeldriver Jan 31 '20 at 15:03%
is special char for cron and there must be \ before this char, so\%
is correct, just for info. And aboutfor
, what is better way to do it? It is only backup for all folders in/var/www/html
, every folder to separated file, for example folderaa
toaa.tar.gz
, folderbb
tobb.tar.gz, etc
. – genderbee Jan 31 '20 at 15:08for i in */;
should work fine. – Terrance Jan 31 '20 at 15:10tar zcvf "${i%%/}.tar.gz" "$i"
– steeldriver Jan 31 '20 at 15:30