-   Linux - Newbie (
-   -   login message shell script? (

jczr2 05-25-2003 10:58 AM

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!

david_ross 05-25-2003 11:11 AM

How about this?

DATE=`date +"Today is %A %D, and it is now %R"`;
echo Welcome $USER. $DATE

jczr2 05-25-2003 11:12 AM

i have been trying it sort of like that, but where do i save it and what extension do i save it as?

david_ross 05-25-2003 11:17 AM

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/", chmod the file 755 and then you just need to put "" 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:

jczr2 05-25-2003 11:28 AM

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.

acid_kewpie 05-25-2003 11:28 AM

you should add it to /etc/bashrc, not to everyones own bashrc.

david_ross 05-25-2003 11:35 AM


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.

date +"Welcome $USER. Today is %A %D, and it is now %R";

jczr2 05-25-2003 11:36 AM

i will try that, but i want it to say welcome to each username, not a gereric for each one.'

david_ross 05-25-2003 11:40 AM

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.

jczr2 05-25-2003 11:42 AM

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.

acid_kewpie 05-25-2003 11:47 AM

are you using bash? show us what the last few lines of bashrc are.

jczr2 05-25-2003 11:47 AM

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

acid_kewpie 05-25-2003 11:49 AM

on what gui??

jczr2 05-25-2003 11:50 AM

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

jczr2 05-25-2003 11:51 AM

sorry, in the red hat 7.3 linux gui

All times are GMT -5. The time now is 03:18 AM.