LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 05-08-2017, 09:31 PM   #1
soumitra1965
LQ Newbie
 
Registered: May 2017
Posts: 2

Rep: Reputation: Disabled
Linux shell scripting using .profile to show customized welcome message to logged in users based on time


How to write a Shell Script to say Good Morning/Afternoon/Evening as you log on in the system?.
 
Old 05-09-2017, 01:49 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
what have you tried?
show us an example, what it does, where it fails.
 
Old 05-09-2017, 09:33 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
this might help if you know how to transpose
https://unix.stackexchange.com/quest...ts-with-ranges

Last edited by BW-userx; 05-09-2017 at 11:21 AM.
 
Old 05-09-2017, 11:14 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by soumitra1965 View Post
How to write a Shell Script to say Good Morning/Afternoon/Evening as you log on in the system?.
Read the "Question Guidelines" link in my posting signature. We're happy to help you with your scripts, but we will NOT write them for you. Post what you have written/done/tried on your own, and tell us where you're stuck.

Otherwise, there are THOUSANDS of easily-found bash scripting tutorials you can find with a brief Google search to get you started.
 
Old 05-10-2017, 06:22 AM   #5
soumitra1965
LQ Newbie
 
Registered: May 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Shell scripting

Hi,
Requirement is like this: while user logs into linux($ prompt), system will welcome him/her by saying good morning/good afternoon/good evening just before S prompt is shown. I have written a shell script welcome. It contains shell coding like now=`date +%H1 if test $now -le 12 then
echo "Good Morning, $LOGNAME" elif test now -le 16 then echo "Good Afternoon, $LOGNAME" else echo "Good Evening, $LOGNAME" fi. Now I want to place this sh welcome code into /home/.profile file for the required result. How to proceed? Pl suggest.

Soumitra Rakshit
 
Old 05-10-2017, 07:39 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,802

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
please use [code]here comes your script[/code] tags to keep formatting of your script. Otherwise it will be really hard to read/understand.
I do not really understand: what is your actual problem?
 
1 members found this post helpful.
Old 05-10-2017, 07:43 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by soumitra1965 View Post
Hi,
Requirement is like this: while user logs into linux($ prompt), system will welcome him/her by saying good morning/good afternoon/good evening just before S prompt is shown. I have written a shell script welcome. It contains shell coding like now=`date +%H1 if test $now -le 12 then
echo "Good Morning, $LOGNAME" elif test now -le 16 then echo "Good Afternoon, $LOGNAME" else echo "Good Evening, $LOGNAME" fi. Now I want to place this sh welcome code into /home/.profile file for the required result. How to proceed? Pl suggest.
Again, you need to read the "Question Guidelines" link, and the LQ Rules...pay attention to the part about text-speak, and not using it, and about posting your code in CODE tags to make things easy to read.

And this post itself makes no sense...you just SAID "I want to place this sh welcome code into /home/.profile"....so DO IT. Open the file...insert the code...save and exit. Where is the difficulty?? And again, please show effort of your own; this is obviously a homework question, and doing even a small amount of research about the Linux login process would tell you what file(s) you need to look at, and give you examples. Your .profile and/or .bashrc are in the home directory for your user ID, like /home/user1/. If you want to apply this for the ENTIRE system, then you need to modify the system profile, in /etc.
 
Old 05-11-2017, 01:31 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by soumitra1965 View Post
Requirement is like this:
telling us your requirements is not my definition of showing some effort.

but anyhow, i copy-pasted the script and formatted it a little:
Code:
#!/bin/sh

now=`date +%H1
if test $now -le 12 
then
echo "Good Morning, $LOGNAME" 
elif test now -le 16 
then 
echo "Good Afternoon, $LOGNAME" 
else 
echo "Good Evening, $LOGNAME" 
fi
needless to say, it doesn't work like that.
 
Old 05-11-2017, 07:56 AM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
yeah when I run that date command I get 3 chars
Code:
good morning userx   <--- but the way I wrote it using a case. It works for me. :D 
userx%slackwhere ⚡ ~ ⚡> date +%H1
071
 
  


Reply



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
Homework Help: customized mail message to logged in users boygenuis Programming 4 03-16-2014 11:07 AM
Linux Shell Script Help! Add uptime logged users. AprendizZ Programming 1 03-07-2012 07:56 PM
"who -a" does not show all users that is logged in on Linux 9 eswanepoel Linux - General 4 11-14-2007 01:01 AM
Shell Scripting: Users "**Never logged in**" cparker15 Linux - General 1 10-02-2003 03:48 PM
Remote message: User: already logged onto system 1 time(s). jamaso Linux - General 1 11-08-2002 05:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

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