LinuxQuestions.org
Review your favorite Linux distribution.
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, 10: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, 11:11 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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, 11:12 AM   #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, 11:17 AM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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, 11:28 AM   #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, 11:28 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you should add it to /etc/bashrc, not to everyones own bashrc.
 
Old 05-25-2003, 11:35 AM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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 11:40 AM.
 
Old 05-25-2003, 11:36 AM   #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, 11:40 AM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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, 11:42 AM   #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, 11:47 AM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
are you using bash? show us what the last few lines of bashrc are.
 
Old 05-25-2003, 11:47 AM   #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, 11:49 AM   #13
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
on what gui??
 
Old 05-25-2003, 11:50 AM   #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, 11:51 AM   #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 7 10-21-2015 10:09 AM
Exiting the Shell script with Error MEssage sumitarun Programming 5 04-14-2005 01:10 AM
Use a shell script to do login and other commands jpan Linux - General 15 01-12-2005 06:52 AM
how to produce pop-up message box / alert window from shell script peb Linux - Newbie 3 02-25-2004 03:14 AM
Shell script login command? chup Linux - General 3 08-24-2003 06:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:24 AM.

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
Open Source Consulting | Domain Registration