Need help with Bash scripting using nano editor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with Bash scripting using nano editor
# 1  
Old 09-30-2011
Need help with Bash scripting using nano editor

p { margin-bottom: 0.08in; } As you can already tell I am a newbie. I took a Microsoft VB2008 a few month back. Now I'm taking Linux + and this course requires me to write scripts. The script executes but, I can't figure out or have not found anything that I can make out on the internet that can answer my questions.


1 I need to make this two statements: if [ "$user_ID" = jcs ] && [ "$password" = 123456 ]
2 If they enter anything other than y they should get message Goodbye
3 Any comments would be appreciated.
4 I would like to add a counter

Code:
 #!/bin/bash
 # Date: 09/25/2011
 # Purpose: Authenticate  
 # Creator: JCS
 # Lasted Changed: 09/25/2011
 clear
 echo -n -e "\n\n\nPlease enter you ID:     "
 read user_ID
 clear
 echo -n -e "\n\n\nPlease enter your password     "
 read password
 clear
 *****if [ "$user_ID" = jcs ] && [ "$password" = 123456 ]; then     
 echo -e "\n\n\nYou have been authenticated."
 else
 echo -n -e "\n\n\nThere is a problem with your authentication. Would you like to try again, enter y for yes."
 read answer
 fi
 while [ "$answer" = y ];
 do
 echo -e "\n\n\nPlease enter you ID:     "
 read user_ID
 clear
 echo -e "Please enter your password     "
 read password
 clear
 if [ "$user_ID" = jcs ] && [ "$password" = 123456 ]; then
    echo -e "You have been authenticated."
 else
 ***echo -e "There is a problem with your authentication. Would you like to try again. Enter y for yes"
 read entry
 fi
 done


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 10-01-2011 at 05:55 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 10-01-2011
Code:
#!/bin/bash
display()
{
  clear
  if [ -z "$choice" ] || [ "$choice" == "Y" ]
  then
    echo -e "Please enter your ID : \c"
    read user_id
    echo -e "Please enter the password : \c"
    read passwd
  else
    exit 0
  fi
}
while true
do
  display
  if [ "$user_id" == "jcs" ] && [ "$passwd" == "123" ]
  then
    echo -e "You have been successfully authenticated!"
    exit 0
  else
    echo -e "Authentication failed!"
    echo -e "Do you want to retry ? (Y or N) : \c"
    read choice
    display
  fi
done

You can beautify the display part.
--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 10-01-2011
Thank you ahamed101, it worked great.Smilie Where can I get more information on the use of the option -z and
[ -z "$choice" ]
display()
{}
I would like to learn more about this functions.
again a million thanks.Smilie
# 4  
Old 10-22-2011
Thank you it worked.
# 5  
Old 10-23-2011
You are welcome!

For scripting, check this
For test operators, check this

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Vim, vi and nano editor shows help.txt automatically

Hi, Whenever i try to open a file in any editor like vi, vim and nano i get this help.txt showing up in split screen without any key being pressed. This continues to pop up even when i close the help.txt. This behavior happens only when i am connected via putty. Is there a fix to this issue? ... (1 Reply)
Discussion started by: sunil0391
1 Replies

2. Homework & Coursework Questions

Bash Scripting

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Try running 'phone4 xyz' and see what happens. Modify your program so that if no matching name is found, an... (1 Reply)
Discussion started by: OmgHaxor
1 Replies

3. Shell Programming and Scripting

bash scripting

same script: 1- i am using grep to find a string called: tinker panic 0 in a file /etc/ntp.conf if the string is not there, i want to add the strings in /etc/ntp.conf file in the first line of the file. if not do nothing or exit. 2- also i want to add # in front of the following lines in... (0 Replies)
Discussion started by: lamoul
0 Replies

4. Shell Programming and Scripting

bash scripting help

Hi Guys i have a <script?> that spits out the location of each printer using snpget here is the code for i in `sed -n '/Start Printer/,/End Printer/p' /hosts/blah/etc/dhcp/hosts.conf | awk '!/^#/ {print $2}' | egrep -v \... (2 Replies)
Discussion started by: ab52
2 Replies

5. Shell Programming and Scripting

[Solved] Help with running ps -e | less on nano script editor

p { margin-bottom: 0.08in; } This is just a portion of a script I'm writing on Linux nano script editor. When I run the script I get stuck on the ps -e | less command portion of the script:wall:. It displays all the process running but it does not allow me to move to the next line on the script.... (2 Replies)
Discussion started by: SANA4SPA
2 Replies

6. Shell Programming and Scripting

Bash scripting

Try to imagine a flag: nnnnx nnnxx nnxxx nxxxx now imagine how it will output: 4 times the "n"and 1 times "x" 3 times "n"and" 2 times" x " .. etc. .. rhombus is the same only instead of "n" is there gap "and " x "is a few times to form the correct shape Can you help... (3 Replies)
Discussion started by: krcek12
3 Replies

7. Shell Programming and Scripting

bash scripting help

have this code but when i run it i get this error ./pulse: line 2: and here is the code #!/bin/bash if ; then pulseaudio -k; fi what am i doing wrong thanks Adam (5 Replies)
Discussion started by: ab52
5 Replies

8. Shell Programming and Scripting

please help with Bash Scripting????

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name) ... (2 Replies)
Discussion started by: eminjan
2 Replies

9. Shell Programming and Scripting

Bash Scripting

Hello there peeps: There is a little piece of bash shell scripting problem i have, which i was hoping you could help me with. #!/bin/bash stored_word() { case $(( $$ % 8 )) in 0 ) echo "energy";; 1 ) echo "touch";; 2 ) echo "climbing";; 3 ) echo... (3 Replies)
Discussion started by: keyvan
3 Replies
Login or Register to Ask a Question