LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-25-2003, 11:58 AM   #1
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Rep: Reputation: 0
login message shell script?


I am a newbie to the Linux world, and I need to make a shell script that will display "Welcome (username), today is (date), and it is now (time)"
I went and bought 3 books, with not much help there, and did search after search, and can't figure it out. Please Help!
thanks
jczr2
 
Old 05-25-2003, 12:11 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
How about this?
Code:
#!/bin/bash
DATE=`date +"Today is %A %D, and it is now %R"`;
echo Welcome $USER. $DATE
 
Old 05-25-2003, 12:12 PM   #3
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
i have been trying it sort of like that, but where do i save it and what extension do i save it as?
thanks
 
Old 05-25-2003, 12:17 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Just put the last 2 lines of the code at the end of each users ~/.bash_profile script. Or probably better is to save the above code into a file called "/bin/welcome.sh", chmod the file 755 and then you just need to put "welcome.sh" at the bottom of the users .bash_profile files. This also gives you the option to change it for all users in one place.

If you want to make it the default for new users then put the per user code at the bottom of:
/etc/skel/.bash_profile
 
Old 05-25-2003, 12:28 PM   #5
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
i am way confused, i understand the script, but there are 15 users and how do i use pico to edit thst snd add those lines of code to it. I just started learning linux 1 month ago, so i'm not too great with it.
thanks
 
Old 05-25-2003, 12:28 PM   #6
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 should add it to /etc/bashrc, not to everyones own bashrc.
 
Old 05-25-2003, 12:35 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Quote:
Originally posted by acid_kewpie
you should add it to /etc/bashrc, not to everyones own bashrc.
Good point but only if you want it to run for all users.

As a side note you could also shorten the code I suggested earlier.
Code:
date +"Welcome $USER. Today is %A %D, and it is now %R";

Last edited by david_ross; 05-25-2003 at 12:40 PM.
 
Old 05-25-2003, 12:36 PM   #8
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
i will try that, but i want it to say welcome to each username, not a gereric for each one.'
thanks
 
Old 05-25-2003, 12:40 PM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
The $USER will pull the username that you are logged in as so you can put it in /etc/bashrc like acid_kewpie said if you want.
 
Old 05-25-2003, 12:42 PM   #10
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
ok, i added the shortened line to the end of the /etc/bashrc in pico, and logged out and back in , and nothing came up.
 
Old 05-25-2003, 12:47 PM   #11
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
are you using bash? show us what the last few lines of bashrc are.
 
Old 05-25-2003, 12:47 PM   #12
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
when i open the terminal window, it says welcome root. date +"Today is %A %D, and it is now %R"
at the top of the window. I was hoping to get it on the gui when it starts up
 
Old 05-25-2003, 12:49 PM   #13
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
on what gui??
 
Old 05-25-2003, 12:50 PM   #14
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
at the terminal, i typed pico /etc/bashrc and a long script came up, and the last line before i added one says : # vim:4:sw=4
 
Old 05-25-2003, 12:51 PM   #15
jczr2
LQ Newbie
 
Registered: May 2003
Posts: 20

Original Poster
Rep: Reputation: 0
sorry, in the red hat 7.3 linux gui
 
  


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
How to check in a script whether the shell is login or non login? frankie_DJ Programming 5 09-06-2005 07:01 AM
Exiting the Shell script with Error MEssage sumitarun Programming 5 04-14-2005 02:10 AM
Use a shell script to do login and other commands jpan Linux - General 15 01-12-2005 07:52 AM
how to produce pop-up message box / alert window from shell script peb Linux - Newbie 3 02-25-2004 04:14 AM
Shell script login command? chup Linux - General 3 08-24-2003 07:43 PM


All times are GMT -5. The time now is 06:31 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