LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 10-24-2002, 06:44 AM   #1
tmz
LQ Newbie
 
Registered: Oct 2002
Posts: 3

Rep: Reputation: 0
send eamil when computer restarts


Hi!

I've just set up my linux. Now I would like that it notifies me, when it restarts.
Can you give me a hint or tell me some links where I could read about this?

Thank you!

TMZ
 
Old 10-24-2002, 08:38 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,709
Blog Entries: 54

Rep: Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965Reputation: 2965
Well, first you would like to get aquainted with the difference in runlevels (man init). Then you've got to decide if the box is able to (still) send an alert at that stage (network up).
Then you gotta write the script that will allow you to send the alert. If you reboot all applications are sent the TERM signal, and within a predefined timespan the KILL signal if they don't respond. This means your window for sending the message is small. You can compensate by running sendq when rebooted.
On a SYSV system you'd link the script from /etc/rc.d/init.d to /etc/rc.d/rc6.d/S01<scriptname> so it'll be the first one accessed.
Here's an example, untested so YMMV:
#!/bin/sh
# Check runlevel
if [ "$(/sbin/runlevel | awk '{print $2}')" != "6" ]; then exit 1; fi
# Check networking still is up
ifconfig eth0 | grep -qe "UP"; net_up="$?"
if [ "$net_up" != "0" ; then exit 1; fi
# Send msg, only Subject necessary
/bin/true | mail -s "Reboot at $(/bin/date)" <address@domain>
# Exit with the exitcode of our last action
exit $?
 
Old 10-24-2002, 09:54 AM   #3
tmz
LQ Newbie
 
Registered: Oct 2002
Posts: 3

Original Poster
Rep: Reputation: 0
Hi!

If I understand correctly, you suggest to send email befor computer goes down. I wouldn't go so far. I just need to be mailed when the system is up again. When every service is up again, the system should send me email "I'm up again".

Do I have to write this <<script file>> in C++ and compile it, or is there an easy way.

Thank you!


Tomaz
 
Old 10-24-2002, 01:38 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
you don't write script files in c++, c++ is a programming langauge, not a scripting language. the example script that unspawn gave nearly does what you asked, to convert it to send the mail when you load, you should place it in etc/rc.d/rc3.d/S99<scriptname> (or 5 if you boot to X) instead of rc6.d, and also change what runlevel you are checking for (i.e. 3 or 5 instead of 6).

you might prefer a simpler approach however (sending a mail on reboot is slightly more complex...) you can just add a simple line such as:

/bin/true | mail -s "Boot at $(/bin/date)" <address@domain>

to the end of a start up script such as /etc/rc.local but naturally that is less rigorous than the previous example, and not as elegant either.
 
Old 10-28-2002, 06:51 AM   #5
tmz
LQ Newbie
 
Registered: Oct 2002
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you. That's what I need.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Alt Delete Restarts Computer, how to fix? PeaceTank Linux - Software 1 02-22-2005 02:00 AM
computer restarts, why? Zhou Yi Linux - Hardware 7 12-14-2004 04:45 AM
Computer Restarts after Extracting Linux Images RoninBlade Fedora - Installation 1 07-28-2004 08:30 AM
Restarts my computer, but it has high enuf spec antibill Fedora - Installation 4 07-18-2004 06:29 AM
F2 Kernel restarts computer during installation Zakalidas Fedora 0 07-06-2004 01:09 PM


All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration