Help on a login script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on a login script
# 1  
Old 04-10-2008
Help on a login script

I am trying to get a script together so when any user logs into the system it will display a message. After the user answers the question based on the answer they will proceed into the system or be logged out. I only want the person to get prompted once per message. Below is what I have in all the users .bash_profile

#!/bin/bash
#set -x

DATE=`date +"%Y/%m/%d %H:%M"`

USER=`who am i | cut -c1-8`

stty erase ^H




clear

echo ""
echo " GT TCY Message of the Day"
echo ""


echo "**Are you familiar with the new docs on opsdoc website???"
echo ""
printf "Please enter Yes or No : "
read ANSWER
echo ""
echo ""

if [[ $ANSWER = "Yes" ]] || [[ $ANSWER = "YES" ]] || [[ $ANSWER = "yes"
]]
then
echo "Thanks, Have a good day..."
exit 1
# read ANSWER
echo ""
echo ""
else
echo "Please review docs and come back later"
sleep 3
skill -KILL -u $USER

fi



Any help would be greatly appreciated.
Thanks
Greg
# 2  
Old 04-10-2008
If you are having a problem, it's usually a good idea to describe what happens and how you think it's wrong.

The "exit" you have in the "have a good day" part will also exit the session, more elegantly than the kill. Just fall out of the conditional and it should work.

Anyway, skill seems excessive (if they have another session open, won't it kill that one too?), and simply exiting also gets rid of the rather silly guessing of the user. (Hint: $LOGNAME should already be set to the current user, but let's not dwell on that.)

It would seem like a good idea to include the URL for the documents you are referring to.

The if is a bit ugly, case is often more elegant when it comes to pattern matching.

Code:
case $ANSWER in [Yy][Ee][Ss] | [Yy]) echo "Thanks, have a good day";;
  *) echo Please review docs and come back later"
     sleep 3
     exit;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script as login shell (passing args to login shell)

Hello all, for security reasons my compagny imposes that my script be launch remotly via ssh under the users login shell. So serverA launches the ssh command to serverB which has a local user with my script as a login shell. Local script works like a charm on his own. serverB$ grep... (20 Replies)
Discussion started by: maverick72
20 Replies

2. Shell Programming and Scripting

Help with login script.

Guys I need to write a script that will login to over 480 servers and run the last -n 45 "userid" | tail -1. OK, I am terrible at writting scripts. So I need the script to run this command and forward the output to my main server in /var/tmp/output. PLEASE HELP. :confused: (7 Replies)
Discussion started by: terrywhitejr
7 Replies

3. OS X (Apple)

Login/Logout script

Dear readers I use SnowLeopard 10.6.2 and need to do some special tasks at login and logout of an sepcific user. My problem is, how do I send a string "login" respectively "logout" from computer "A", where the login/logout script runs, to computer "B" where some other tasks need to be done. ... (3 Replies)
Discussion started by: tthaler
3 Replies

4. Programming

Login script for unix ?

Anyone know of a script or program in a unix platform that will allow one login and password for three databases ? Say i have a social site that has a video site and phpBB3 forum but i want them connected as one login. I heard there is a script that does that , anyone know the name or where to get... (0 Replies)
Discussion started by: rumrunner439
0 Replies

5. Shell Programming and Scripting

Login Script

Can anybody help in writing a script that takes username and password and then successfully login onto windows operating system box? For example 1. I have a box A with Linux OS. 2. I have another box B with windows OS. How to login onto boxB from boxA? (3 Replies)
Discussion started by: vinna
3 Replies

6. Shell Programming and Scripting

How can we ssh login with script?

Hi all, Normally, we give ip address to login with ssh like ssh 172.168.0.1 And we can give login name to ssh like ssh -l root 172.10.0.21 Then the shell asks the password, we enter the password and login to the system. While using the script file, we are not able to supply the password to... (5 Replies)
Discussion started by: pcsaji
5 Replies

7. Shell Programming and Scripting

Automatic login script

Hi, I'm a beginner in unix.As a part of my script i need to remote logon using ssh. my script run as being asked for password and logons only after the user enters the password correctly. But my script stops executing after that as I login to a different server(different shell if i'm right).... (3 Replies)
Discussion started by: dayanand
3 Replies

8. UNIX for Dummies Questions & Answers

Login script

Hi, I wrote a script for backing up a application database. When I run the script from command line, it works great.. But when I add that script to login profile of some user , it does not work ... ******************************************* backup script:- (databasebk) #!/bin/ksh # set... (3 Replies)
Discussion started by: newtoxinu
3 Replies

9. Shell Programming and Scripting

Script with SU Login

I'm attempting to write a script where it temporarily would login as Super User to change some file permissions, cats the files, then exits. Can this be done by script with no manual(human) input? thanks (3 Replies)
Discussion started by: bkhviking
3 Replies

10. UNIX for Dummies Questions & Answers

Login and logout script

Hi all I know ho I can run a script when a user logs in, viz using the .login or .profile file, however what can I use to run a script when a user logouts ? Thanks J :confused: (1 Reply)
Discussion started by: jhansrod
1 Replies
Login or Register to Ask a Question