Simple Login script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Simple Login script
# 1  
Old 11-11-2014
Simple Login script

Hi Guys

Im new to bash script, trying hard to learn and enjoying this process. However i'm pretty much stumped, so i will put my problems out there. In the hope someone can help me. I am trying to make a bash script that allows users of a Unix system (with little knowledge under the hood ) to be able to easily find there way around simple tasks, they may need to perform.

Before they use this script, i would like them to login first. They would login, if the attempt was successful; then the script would run. But if login was not successful they are taken back to login to re-try.

I'm thinking there needs to be a loop within the login code so as to send them back to try again if unsuccessful . . is this right?? The code i have used for login does not work, whatever i type it says wrong info?

Thanks for any help, my code so far is below . .

Rgds Willo

Code:
#!/bin/bash
clear
echo "********************"
echo "********************"
login=abc
echo "Please Login . ."
read $loginpass
	if [ "$loginpass" = "login" ]
	then
		echo "welcome . . "
	else
		echo "sorry login incorrect!!"
                echo exiting...
                exit 3
	fi
quit=n
while [ "$quit" = "n" ]
do
clear
echo "***************************************"
echo "***********$(tput setaf 6) Unix System$(tput sgr 0) ***************"
echo "***************************************"
echo "***************************************"
echo "$(tput setaf 3)1$(tput sgr 0). Show Date"
echo "$(tput setaf 3)2$(tput sgr 0). Show Calendar"
echo "***************************************"
echo "***************************************"
echo "***$(tput setaf 6) System Unix$(tput sgr 0) ***********************"
echo "***************************************"
echo "$(tput setaf 3)3$(tput sgr 0). Reboot System"
echo "$(tput setaf 3)4$(tput sgr 0). Host name"
echo "$(tput setaf 3)5$(tput sgr 0). IP Address"
echo "$(tput setaf 3)6$(tput sgr 0). Avaiable Memory"
echo "***************************************"
echo "***************************************"
echo "***$(tput setaf 6) User Management$(tput sgr 0) *******************"
echo "***************************************"
echo "$(tput setaf 3)7$(tput sgr 0). Add new User"
echo "$(tput setaf 3)8$(tput sgr 0). Delete a User"
echo "$(tput setaf 3)9$(tput sgr 0). List all Users"
echo "$(tput setaf 3)10$(tput sgr 0). Search User by Name"
echo "***************************************"
echo "***************************************"
echo "***$(tput setaf 6) File Management$(tput sgr 0) *******************"
echo "***************************************"
echo "$(tput setaf 3)11$(tput sgr 0). Create a New File"
echo "$(tput setaf 3)12$(tput sgr 0). Delete a File"
echo "$(tput setaf 3)13$(tput sgr 0). List all Files"
echo "$(tput setaf 3)14$(tput sgr 0). Creata a New Dir"
echo "$(tput setaf 3)15$(tput sgr 0). Delete a Dir"
echo "***************************************"
echo "***************************************"
echo "***$(tput setaf 6) Network Management$(tput sgr 0) ****************"
echo "***************************************"
echo "$(tput setaf 3)16$(tput sgr 0). Show ARP Table"
echo "$(tput setaf 3)17$(tput sgr 0). Ping a Remote Machine"
echo "***************************************"
echo "***************************************"
echo "Please pick a Choice . ."
read choice
case $choice in
	1)date
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	2)cal
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	3)reboot
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	4)hostname
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	5)ip addr show
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	6)df -h | awk '{print $4}'
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	7)echo "Please Enter the New Users Name . . "
	read usersname
	su Willo009 -c useradd $username
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	9)users
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	11)echo "Please Enter New File Name . ."
	read newfilename
	vi $newfilename;;
	12)echo "Please Enter a File Name to Delete . ."
	read deletefile
	rm $deletefile
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	13)ls
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	14)echo "Please Enter a New Dir Name . ."
	read newdir
	mkdir $newdir
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	15)echo "Please Enter a Dir Name to Delete . ."
	read dirdel
	rmdir $dirdel
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"
	read junk;;
	17)echo "Enter Ip to Ping . ."
	read userping
		if ! ping -c 1 -w 5 "$1" &>/dev/null
		then
			echo "$userping is down"
		else 
			echo "$userping is up"
		fi
	echo -e "Hit the$(tput setaf 1) Enter Key$(tput sgr 0) to continue"

	read junk;;
esac
done
echo "Program has Finished"


Last edited by vbe; 11-11-2014 at 12:39 PM.. Reason: typos - missing square braket...
# 2  
Old 11-11-2014
Try your script with the red braket:
Code:
	if [ "$loginpass" = "login" ]

... And send us what error is displayed...
# 3  
Old 11-11-2014
Hi vbe
Thanks for your time, with the bracket. When i run the code no matter what i put its taking me to "wrong login info . . " but then runs the script below anyway. I really need it to allow past to the Main script only if $loginpass is "abc". And if not "abc" to restart at the login stage.

Willo
# 4  
Old 11-11-2014
I added in your script, in your first if / else an exit in red - Try now...
# 5  
Old 11-11-2014
Yes i have added this code in red,
Still goes to "Wrong login . . . " and then exits back to bash $
# 6  
Old 11-11-2014
line 7 :
Code:
read $loginpass

Should be:
Code:
read loginpass

But now you exit as wished hehe
# 7  
Old 11-11-2014
haha yes i have already learned something new the exit command, which i did not know before so thankyou for that my friend.
 
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. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

3. Shell Programming and Scripting

Simple check login script

Hello, I just started with shell and i am doin simple script to check if certain user is logged in. Script takes 3 args. name sleep time and quit value if there is q for quit then date and user name is printed to file, not to screen. so far i have got this... login() { while :... (3 Replies)
Discussion started by: shelllo
3 Replies

4. Fedora

Simple login script in openSuSe

Hi guys, Ok so I'm basically trying to run a script on loging or after everything else has started up, I've done so much googling my head is spinning I don't understand the which file I have to edit with the details of my script, In suse there is no etc/profiles folder its daemonised so its... (1 Reply)
Discussion started by: whitenight639
1 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Web Development

Simple Login page

Hi all, I am stepping into web-development as a hobby point of view. I am using WAMP server & have created the initial page & SQL set-up too. My problem is, I was able to login to a page/redirect to a page though I haven't specified my username & password. I thought of using both... (2 Replies)
Discussion started by: gameboy87
2 Replies

7. Shell Programming and Scripting

Simple Script Can u help please?

I have a file that contains these lines User ID Username -------- ---------- 7738626,zrazak 7783535,jvincigu 7805567,ldrennan 7805583,mtsakama I need to sort the names alphabetically How can I sort the lines based on the user names ? I would appreciate a quick reply anyone ... (1 Reply)
Discussion started by: mnassiri
1 Replies

8. UNIX for Dummies Questions & Answers

Simple script

Hi All, First time poster so be gentle - Also apologies if this is in the wrong section. I am not a unix administrator but as a Storage administrator know enouh to get me by for what I need to do. However I am having a slow night-shift so I am playing about with a bit of scripting to... (7 Replies)
Discussion started by: colinwilson1303
7 Replies

9. Shell Programming and Scripting

I need a simple script

Hi, I need a script which can apply 'cd' command . for example there is a directory: (myDirectory) #cd myDirectory (current dir is myDirectory) my script can do this: #do (current dir is myDirectory) (do is my script) Thanks. (2 Replies)
Discussion started by: mehmetned
2 Replies

10. UNIX for Dummies Questions & Answers

something simple, but i have no idea: a login issue

Hi all, I have a problem not really dramatic but realyl annoying: i've got a groups of users who logon a sunos 2.3 box via a windows telnet client (KEAI, but this is not the problem). they login as perso1 and password. It takes a very very very long time to get in. If i log on the same box... (2 Replies)
Discussion started by: penguin-friend
2 Replies
Login or Register to Ask a Question