[ncolug] Re: Linux Home Automation

Mike wrote:

Replying to myself...

I walked away and figured out I gave out conflicting information. Use mktemp, then you won't have fuss with the file names. They are handled there.

The date info still applies IMNSHO if you are creating the files.

Commented on testing for the existence of files and/or redirecting output. One can redirect STDOUT and STDERR in the crontab file. This will prevent you getting mail if any output is generated. This isn't the best thing to do unless the output is meaningless. I like to have the script catch any output or redirect it, then if something goes awry during a run of cron you will get a mail that will be useful.

Other tidbits more applicable to multi user systems. Quit using ~/bin for other than test purposes. Ask Chuck for a dissertation on the headaches this will cause you, and to why it is a very bad practice. I'm not going there.

I'd also use /tmp or /var/tmp for the files, again not ~/something. Using either should include a test to ensure that the directory exists before trying to write files to it. Yes it is a bit more work, it goes back to using ~ again.

A script this short I probably wouldn't do the following on Linux. Other *nix systems I would. I do this because I want to know *exactly* what tool I'm calling. On the Solaris boxen at MSC one could find up to 4 different versions of a given tool. It ain't pretty when you get the wrong one due to a PATH issue. All that said, what I do is set variables for each tool called and then reference the variable. Something like this.

LS=/usr/local/bin/ls
RM=/bin/rm

${LS} -1 /somedir/* | ...

I also tend to get rather anal and use ${} when using variables. Certainly not required, it helps me with readability and there is some reasoning to the usage in my brain.

Mike

To unsubscribe send to ncolug-request@xxxxxxxxxxxxx with 'unsubscribe' in the 
Subject field.

Other related posts: