How to redirect stderr to a file in a cron job

It’s the other way around: */1 * * * * sudo /home/pi/coup/sensor.py >> /home/pi/sensorLog.txt 2>&1 2>&1 will redirect standard error (2) to standard output (1) which -in turn – was redirected to your log file. So, at the end, both stderr and stdout will go to your sensorLog.txt

Today’s date, minus X days in shell script

For GNU date: date_222days_before_TodayYear=$(date –date=”222 days ago” +”%Y”) date_222days_before_TodayMonth=$(date –date=”222 days ago” +”%m”) date_222days_before_TodayDay=$(date –date=”222 days ago” +”%d”) For BSD date:: If you are using OS X or FreeBSD, use the following instead because BSD date is different from GNU date: date_222days_before_TodayYear=$(date -j -v-222d +”%Y”) date_222days_before_TodayMonth=$(date -j -v-222d +”%m”) date_222days_before_TodayDay=$(date -j -v-222d +”%d”) Source: BSD …

Read more

sh read command eats backslashes in input?

Accrding to: http://www.vias.org/linux-knowhow/bbg_sect_08_02_01.html : -r If this option is given, backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation. It works on my machine. $ echo ‘\&|’ | while read -r in; do …

Read more