This cron cannot be executed: * * * * * */bin/echo '/bin/date + "%y-%m-%d-%t" ' >>/home/adminuser/test.txt 2>&1 need to be modified to: because% is required in cron To be transferred */1 * * * */bin/echo/bin/date + "\%y-\%m-\%d-\%t" >>/home/adminuser/test.txt 2>&1 detect disk and folder usage: */ * * * * echo ' date + ' \%y-\%m-\%d-\%t ' '/home/adminuser '/bin/df-h/home/adminuser | /bin/grep/dev/sda1 | Awk-f ' {print ' free: ' $ $ ' usage: ' $4} ' >>/HOME/ADMINUSER/DF.TXT*/30 * * * * echo ' date + ' \%y-\%m-\%d-\%t ' '/usr ' /bin/du-h--max-depth=0/home/adminuser ' date + ' \%y-\%m-\%d-\%t ' >>/home/adminuser/du.txt detailed explanation:
The purpose of this document are to explain how to cope with the percentage sign (%) in a crontab entry.
Usually, a used to denote a new line in a crontab entry. The first is special on that it denotes the start of STDIN for the crontab entry ' s command. A Trivial example is:
* * * * * cat-% another minute has passed
This would output the text
Another minute has passed
After the first percent, all other%s in a crontab entry indicate a new line. So a slightly different trivial example is:
* * * * * cat-% Another% minute% has% passed
This would output the text
Another minute has passed
Note how the% have been used to indicate a new line.
The problem is about use a% of a crontab line to as a% and not as a new line. Many manuals would say escape it with a \. This certainly stops it interpretation as a new line and the shell running the cron job can leave the \ in. For example:
* * * * * echo ' \% another \% minute \% has \% passed '
Would output the text
\% another \% minute \% has \% passed
Clearly, not what is intended.
A solution is to pass the text through SED. The crontab example now becomes:
* * * * * echo ' \% another \% minute \% has \% passed ' | Sed-e ' s|\\| | G
This would output the text
% another% minute% has% passed
which is intended.
This technique was very useful when using a MySQL command within a crontab. MySQL command can often has a% in them. Some example is:
- SET @monyy =date_format (now (), "%M%Y")
- SELECT * FROM table WHERE name like ' fred% '
So, to has a crontab entry to run the MySQL command
mysql -vv -e "SELECT * FROM table WHERE name LIKE Fred%‘" member_list
Would has to appear in the crontab as
echo "SELECT * FROM table WHERE name is like ' fred\% '" | Sed-e ' s|\\| | G ' | MYSQL-VV member_list
Linux cron vs.%