More Quesions: Scripts

Discussion and Technical Support for general software applications and utilities including OS related issues.
Post Reply
softair
Member
Member
Posts: 11
Joined: July 13th, 2012, 2:25 pm

More Quesions: Scripts

Post by softair »

I've been revisiting the various scripts (shut down, SnapRAID) and have a few questions: again, no doubt the answers are obvious to experienced Linux/Ubuntu veterans, but not to this newby...

1. When shutting down because the temperature is too high, your script issues the shutdown request
/sbin/shutdown -h now

BEFORE sending the email
/usr/sbin/ssmtp bob.walton@...

This is counter-intuitive, to say the least! The email does appear to get sent before the shutdown, however!.

2. The shutdown scripts use the ssmtp command to send the email, the SnapRAID scripts uses the mail command. Both work on my system: is there any fundamental difference between them when sending simple text emails (apart from the actual command line interface, that is)?

3. Is there any reason why you run programs by using the full file address such as "/usr/sbin/ssmtp" when "ssmtp" would appear to have the same effect? I guess this may be something to do with the way Ubuntu searches for executables (as per the windows search path) - a subject I know little about. I must try harder: I guess that's why I have to type "./MyScriptFile.sh" rather than just "MyScriptFile.sh" to run something in my Scripts directory.

Answers much appreciated!

TIA

Bob
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: More Quesions: Scripts

Post by Ian »

Hi Bob,

Yet again, very sensible questions.
softair wrote:1. When shutting down because the temperature is too high, your script issues the shutdown request
/sbin/shutdown -h now

BEFORE sending the email
/usr/sbin/ssmtp bob.walton@...

This is counter-intuitive, to say the least! The email does appear to get sent before the shutdown, however!.
It's been a while since I wrote that script so there may have been other reasons but the most crucial thing, for me, is the server shuts itself down if it has started to overheat. Getting an email about this fact is a nice-to-have. I would be concerned that if, somehow, the email command got "stuck" and so control didn't return to the script. If this happened the server would not shut itself down.
softair wrote:2. The shutdown scripts use the ssmtp command to send the email, the SnapRAID scripts uses the mail command. Both work on my system: is there any fundamental difference between them when sending simple text emails (apart from the actual command line interface, that is)?
This is simply one of timing. I first put together the website a year or so ago and ssmtp seemed to be a simple & lightweight tool and so I installed it. A month or so ago I came across that SnapRAID script. I did notice in that script it uses a different mechanism. It's only now you've pointed it out that I'm thinking I really should sort that discrepancy out and just use the one method. :oops: The method in the SnapRAID script offers a lot more flexibility in constructing the email message than in ssmtp (although the latter is a much more lightweight package)
softair wrote:3. Is there any reason why you run programs by using the full file address such as "/usr/sbin/ssmtp" when "ssmtp" would appear to have the same effect? I guess this may be something to do with the way Ubuntu searches for executables (as per the windows search path) - a subject I know little about. I must try harder: I guess that's why I have to type "./MyScriptFile.sh" rather than just "MyScriptFile.sh" to run something in my Scripts directory.
You're on the right track (or path :lol:) with your windows search path thought. When jobs are run via cron different "environment variables" get different values (or no values at all) compared to when an end-user is logged onto the machine. If you specify the full path then not only can you be sure the executable will run but you can be sure the RIGHT executable will be run. There's nothing stopping you having two different EXEs with the same name in different locations. :crazy:

Hope this helps,

Ian.
softair
Member
Member
Posts: 11
Joined: July 13th, 2012, 2:25 pm

Re: More Quesions: Scripts

Post by softair »

1. That's an interesting thought. If the system has stayed up (if hot) for the period since the last check, I guess the chances of it staying up long enough to send the eMail are probably good, and you're down to a (hopefully rarely used) software procedure getting stuck. It's a shame the finest grain on shutdown is 1 minute, otherwise I think I might take a chance on shutting down after a few seconds. (And I'm keeping my server in a cupboard too...).

2. Fair enough!

3. Rather what I suspected.

Many thanks for the comprehensive reply

Bob.
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: More Quesions: Scripts

Post by Ian »

Hi Bob,

sudo shutdown -h now actually commences the shutdown procedure immediately. It takes 5-10 seconds for the procedure to run through closing down all running processes before powering off the machine completely. It's during this time that the email gets fired off. If the email procedure hangs then the shutdown procedure will forcibly kill it (along with anything else that has hung).

I see you're also intending putting your server in a cupboard. Have you done any experimentation to see whether your server gets adequate cooling whilst in there? It took quite a bit of trial and error before I came up with a cooling "circuit" in my cupboard that worked properly. It's a lot more involved than simply cutting a couple of holes in the cupboard to allow airflow believe it or not. If you just plonk your server in there then the warmer air coming out of the back of the server will simply heat the air inside the cupboard up, and thus warmer air will get sucked into the server and even warmer air will get blown out and so on.

Let us know how you get on :thumbup:

Ian.
Post Reply