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

Pipe output to environment variable export command

$1 is used to access the first argument in a script or a function. It is not used to access output from an earlier command in a pipeline. You can use command substitution to get the output of the git command into an environment variable like this: GIT_HASH=`git log –oneline -1` && export GIT_HASH However… … Read more

How can I have a newline in a string in sh?

If you’re using Bash, the solution is to use $’string’, for example: STR=$’Hello\nWorld’ echo “$STR” # quotes are required here! Prints: Hello World If you’re using pretty much any other shell, just insert the newline as-is in the string: STR=’Hello World’ Bash recognizes a number of other backslash escapes characters in the $” string. Here … Read more

“echo -n” prints “-n”

There are multiple versions of the echo command, with different behaviors. Apparently the shell used for your script uses a version that doesn’t recognize -n. The printf command has much more consistent behavior. echo is fine for simple things like echo hello, but I suggest using printf for anything more complicated. What system are you … Read more

tech