Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Please advise if this is possible in a Perl script??
Here is what I use to find out when my Solaris 7 server was last rebooted:
Unix# psrinfo -v Status of processor 0 as of: 03/07/02 12:59:02 Processor has been on-line since 01/23/02 12:23:27. The sparc processor operates at 50 MHz, and has a sparc floating point processor.
But I have to be root to do this. Is there anyway (after the Solaris 7 server is rebooted) to email me and let me know it was rebooted. I want to put this in a cron job to check just once a day and only email me if the server was rebooted. Also I am hoping I wont need root priviledges to do this.

Replies are listed 'Best First'.
Re: Send message after server reboot
by maverick (Curate) on Mar 07, 2002 at 19:20 UTC
    The best way would be to add it to the system start up script. /etc/rc.d/rc.local or something of that sort. If you can't do that, then you can go the cron route.

    Linux (don't know about Solaris) has a command called 'last' that will have a line that shows when the system was rebooted. You can narrow the last output by the user which under Linux is 'reboot'. So 'last -1 reboot' would give you the last time the system was rebooted.

    The other thing you need to do is keep track of the last reboot time that a notification was sent for, so that you don't double send.

    HTH

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

Re: Send message after server reboot
by scain (Curate) on Mar 07, 2002 at 18:47 UTC
    Well, there are a couple of things you could do. You can talk the sysadmin of the box into putting a script in the startup routine to send an email, or you can do what you suggested and run a cron job and have it send an email. Either way, look into Mail::Sendmail.

    As for system commands, a simple command like w or uptime will report uptime. You could get the outout with backticks and parse out the uptime. If it is less than a day, send you the email.

    Good luck
    Scott

Re: Send message after server reboot
by dws (Chancellor) on Mar 07, 2002 at 18:47 UTC
    uptime | mail user@example.com