Archives for posts tagged ‘bash’

crontab/date: timestamp in log file name

A cronjob shall run a script and write it’s output to a new logfile every day. Easy, right?
0 2 * * * echo test > test.`date +%Y-%m-%d`

This will create a file called “test.“, that will be overwritten every day …and here is why (from man crontab):
“Percent-signs (%) in the command, unless escaped with backslash (\), [...]

Solaris/bash: “no: command not found”

At work we have a script, that rsyncs a bunch of files from one server to the other, nothing special. The script works perfectly when run manually from a shell, but does not when run via crontab. The error message does not really point to anything:
no: command not found
What is the “no” command and why [...]

find magic: recursive delete and chmod

You can do a lot of cool things with find combined with the -exec parameter:

recursive chmod of only directories
find . -type d -exec chmod 755 {} \;
recursive chmod of only files
find . -type f -exec chmod 644 {} \;
recursive delete of all txt files
find . -name ‘*.txt’ -exec rm {} \;

(edited due to popular demand.)