Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

message of the day question

Status
Not open for further replies.

fenris

Programmer
May 20, 1999
824
CA
I have a question that I can't find the answer for. I am running mandrake 7. In the message of the day ie the login message, how would I display the uptime of the box?<br><br>For example: <br><br>This machine has been up for xxxx days<br><br>where xxxx is the number of days the machine has been. Or alternatively I would like to display the results of running uptime.<br><br><br>thanx.... <p> fenris<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
 
You could maybe set up a &quot;cron&quot; job that would recreate the /etc/motd file once a day, or whatever, so that it contains an almost up to date &quot;uptime&quot; report? <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
How about writing something like:<br><br>#!/bin/ksh<br>#<br>$host=`hostname`<br>$uptime=`uptime ¦awk '{print $3}'`&nbsp;&nbsp;#get days<br>$file=/etc/motd<br>$contact=&quot;your name, your phone#,your email&quot;<br>print &quot;welcome to $host, $host has been up for $uptime days. If you should experience problems with this machine please e-mail or call $contact&quot; &gt; $file<br><br>and putting it in cron to run at whatever interval you want.<br>Our operations dept. asked me to write something they could put in cron to run after the weekly IPL's to let them know which machines actually ipl'd (to see if any were missed) and to ensure they came up properly.&nbsp;&nbsp;It was similar to this.<br>Hope this helped. <p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
 
There are no system variables that would be able to do this. It doesn't look like it would be that easy then...<br><br>Oh well, I could try the cron job, but that would mean I have to learn about it first ;)<br><br>regards, <p> fenris<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
 
the profile script usually (I haven't looked at my linux setup - at home) just does a 'cat /etc/motd'<br><br>so - you could do something like this in /etc/profile<br><br>uptime &gt; /tmp/uptime.tmp.$$<br>cat /tmp/uptime.tmp.$$ /etc/motd<br>rm /tmp/uptime.tmp.$$<br><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Thanks for the information, I will try it when I get home.<br><br>b0rg, the script that you presented, all I would have to do is enter it in vi, save it and then I would have to make it executable and put a reference to it in cron?<br><br>I am familiar with linux to an extent, but when it comes to scripting I have no clue how to implement it.<br><br>Mike,what does /etc/motd do? I understand the rest of the lines, basically your piping the output of the uptime program to a temporary variable, then you cat the temp variable with /etc/motd after that you delete the temp variable. The /etc/profile would hold for all users, or only specific users?<br><br>Again Thank you all... <p> fenris<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
 
fenris,<br><br>&nbsp;&nbsp;&nbsp;Yeah, with my script all your doing is defining basic system information (i.e. hostname) but when you surround &quot;hostname&quot; with bacticks `hostname` you are telling the script to get the systems hostname (`hostname`= my_box.mydomain).&nbsp;&nbsp;The reason I make a variable is so that if you want to add arguments to $host or $uptime you can without having to rewrite the whole thing.<br>&nbsp;&nbsp;&nbsp;&nbsp;Anyway, /etc/motd does nothing but <i>'cat'</i> the file /etc/motd to /dev/console (or whatever standard out is).&nbsp;&nbsp;So with my script in cron it will print <b> &quot;welcome to <i>mybox</i>, <i>mybox</i> has been up for <i>3</i> days.&nbsp;&nbsp;If you should experience problems with this machine please e-mail or call <i>myname myemail myphone </i>.&quot;</b> and redirect the output to /etc/motd.&nbsp;&nbsp;Then you put in a cron job that updates say every 15 minutes.&nbsp;&nbsp;Then when someone logs in they get that information and it's no older than 15 minutes.&nbsp;&nbsp;Of course, doing what Mike suggested would probably work too, it's just less personal.&nbsp;&nbsp;The idea behind motd besides giving information was to make it understandable to the non-technical users who wouldn't necessarily understand what loadaverage is or why they should be concerned with it, and then call you to find out.&nbsp;&nbsp;Of course you don't have to make the script exactly as I wrote that one, it was just an example.&nbsp;&nbsp;Hope I helped you without confusing you, I tend to do that, sorry if I did. <p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
 
So b0rg, I would just have to cat the script to /etc/motd and it would run? I am not new to programming but then again I come from the wonderful world of windows ;) So I am not used to scripts that are powerfull!<br><br>Thanks for all the info... I can't wait to try it...<br><br> <p> fenris<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
 
fenris,<br><br>The file /etc/motd is just displayed, if it exists, when you login.<br><br>The file /etc/profile is a common login file for all users, each user can also have a file called .profile in their home directory.<br><br>You should take care modifying /etc/profile - remember that you have to get through that script in order to login so make sure you don't log out of all root logins before you're sure it works ok.<br><br>Jon,<br><br>I like your script but not sure about the way you suggest running it...<br><br>If you changed the 'print's to 'echo' then your 5 lines could replace the 'cat /etc/motd' in /etc/profile - and you wouldn't have to run the script using cron.... <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Mike, <br><br>&nbsp;&nbsp;Yeah, I guess your right, I was looking at the script I wrote for the cron (actually a MAESTRO) scheduler facility and just didn't change the &quot;print&quot; to &quot;echo&quot;, thanks for catching me and correcting it. <p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
 
Thanks for the help... I appreciate it. I tried both b0rg and Mike's ideas.. They both work great, but Mike's solution was exactly what I was looking for. I agree with borg's statement about user friendlyness but I am the only one using the box so that is not really a priority. Thanks again... <p>Troy<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
 
Your welcome Troy <p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top