Sponsored Content
Full Discussion: Shell Script Password Prompt
Homework and Emergencies Homework & Coursework Questions Shell Script Password Prompt Post 302816613 by vbe on Tuesday 4th of June 2013 09:58:09 AM
Old 06-04-2013
IF I understood correctly the end of your requirement: you need it display AND copying output in a file then you will have to look at the command tee...
The best for you to figure out what it to be done is write in pseudocode how the script should work, submitting here we would help and correct to get you doing what you are asked but dont expect we give you the solution ( even if we are tempted.. haha Its hard for us to not and figure out what/what not to post...)
Your script should be divided in 2 paragraphs:
Code:
# Initialize your variableis:
MYPWD=""
PASS="lux"
PASSCPT=0
.
# Testing condition:
While ..
# 2 possibilities: while passwd is not good OR $PASSCPT -lt 3
# I let you decide... one of course is more legeant than the other...
# Remember that if codition is met to get out by some means 
# e.g using break in a if condition...
..
done

#Post testing treatment # You should enter here only if required condition are met!

ls- l 
.
#Ask username...
# write at end of generated file
End

Waiting to see your new submission!

Courage!


---
ADDENDUM

Result of my little test:
Code:
ant01:/home/vbe/script/test/zz/001 $ ./pwdcheck01 
Please enter the correct passwd, you have 3 tries before exit. you have now: 3  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 2  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 1  tries left.
Password: 
 3 bad attemps, exiting... 
ant01:/home/vbe/script/test/zz/001 $ ./pwdcheck01
Please enter the correct passwd, you have 3 tries before exit. you have now: 3  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 2  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 1  tries left.
Password: 
 3 bad attemps, exiting... 
ant01:/home/vbe/script/test/zz/001 $ ./pwdcheck01
Please enter the correct passwd, you have 3 tries before exit. you have now: 3  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 2  tries left.
Password: lux
Password Accepted after 2  attempt
total 56
drwxrwxr-x    4 vbe      staff         4096 Jun 04 17:30 .
drwxr-xr-x    3 vbe      bin             256 Jun 03 15:52 ..
drwxrwxr-x    2 vbe      staff          256 Jun 03 15:54 002
-rw-rw-r--    1 vbe      staff            0 Jun 04 17:30 check_test001.out
drwxrwxr-x    2 vbe      staff          256 Jun 04 16:34 dir02
-rw-rw-r--    1 vbe      staff          115 Jun 03 15:53 find_sh001
-rwxr-x---    1 vbe      staff         1436 Jun 04 15:12 pwdcheck
-rwxr-x---    1 vbe      staff         2105 Jun 04 17:00 pwdcheck01
-rw-rw-r--    1 vbe      staff            0 Jun 03 15:55 register.txt
-rw-rw-r--    1 vbe      staff         5049 Jun 03 15:55 regular_expr.howto
-rw-rw-r--    1 vbe      staff          867 Jun 03 15:53 rm_sed001
 As you have succeeded, please give your user name :  ^C
ant01:/home/vbe/script/test/zz/001 $ ./pwdcheck01
Please enter the correct passwd, you have 3 tries before exit. you have now: 3  tries left.
Password: lux
Password Accepted after 1  attempt
total 56
drwxrwxr-x    4 vbe      staff         4096 Jun 04 17:30 .
drwxr-xr-x    3 vbe      bin             256 Jun 03 15:52 ..
drwxrwxr-x    2 vbe      staff          256 Jun 03 15:54 002
-rw-rw-r--    1 vbe      staff            0 Jun 04 17:30 check_test001.out
drwxrwxr-x    2 vbe      staff          256 Jun 04 16:34 dir02
-rw-rw-r--    1 vbe      staff          115 Jun 03 15:53 find_sh001
-rwxr-x---    1 vbe      staff         1436 Jun 04 15:12 pwdcheck
-rwxr-x---    1 vbe      staff         2105 Jun 04 17:00 pwdcheck01
-rw-rw-r--    1 vbe      staff            0 Jun 03 15:55 register.txt
-rw-rw-r--    1 vbe      staff         5049 Jun 03 15:55 regular_expr.howto
-rw-rw-r--    1 vbe      staff          867 Jun 03 15:53 rm_sed001
 As you have succeeded, please give your user name :  ^C
ant01:/home/vbe/script/test/zz/001 $ ./pwdcheck01
Please enter the correct passwd, you have 3 tries before exit. you have now: 3  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 2  tries left.
Password: 
Please enter the correct passwd, you have 3 tries before exit. you have now: 1  tries left.
Password: lux
Password Accepted after 3  attempt
total 56
drwxrwxr-x    4 vbe      staff         4096 Jun 04 17:31 .
drwxr-xr-x    3 vbe      bin             256 Jun 03 15:52 ..
drwxrwxr-x    2 vbe      staff          256 Jun 03 15:54 002
-rw-rw-r--    1 vbe      staff            0 Jun 04 17:31 check_test001.out
drwxrwxr-x    2 vbe      staff          256 Jun 04 16:34 dir02
-rw-rw-r--    1 vbe      staff          115 Jun 03 15:53 find_sh001
-rwxr-x---    1 vbe      staff         1436 Jun 04 15:12 pwdcheck
-rwxr-x---    1 vbe      staff         2105 Jun 04 17:00 pwdcheck01
-rw-rw-r--    1 vbe      staff            0 Jun 03 15:55 register.txt
-rw-rw-r--    1 vbe      staff         5049 Jun 03 15:55 regular_expr.howto
-rw-rw-r--    1 vbe      staff          867 Jun 03 15:53 rm_sed001
 As you have succeeded, please give your user name :  Tsadf jkh Osfak
File check_test001.out  User name :   Tsadf jkh Osfak
Tue Jun  4 17:31:18 CEST 2013
total 56
drwxrwxr-x    4 vbe      staff         4096 Jun 04 17:31 .
drwxr-xr-x    3 vbe      bin             256 Jun 03 15:52 ..
drwxrwxr-x    2 vbe      staff          256 Jun 03 15:54 002
-rw-rw-r--    1 vbe      staff            0 Jun 04 17:31 check_test001.out
drwxrwxr-x    2 vbe      staff          256 Jun 04 16:34 dir02
-rw-rw-r--    1 vbe      staff          115 Jun 03 15:53 find_sh001
-rwxr-x---    1 vbe      staff         1436 Jun 04 15:12 pwdcheck
All processing done, file generated is check_test001.out: 
-rw-rw-r--    1 vbe      staff          837 Jun 04 17:31 check_test001.out
ant01:/home/vbe/script/test/zz/001 $


Last edited by vbe; 06-04-2013 at 12:38 PM.. Reason: ADDENDUM
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sudo in OS X shell script without password prompt??

I've written a shell script to alter a particular preference file on OS X (10.3.9), which works fine (tested by running the script from the terminal sat in front of the box). Problem is, I now have to run this script remotely across a number of machines via remote desktop, so where I've used the... (1 Reply)
Discussion started by: Brad_GNET
1 Replies

2. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

3. Shell Programming and Scripting

sudo, use in script without prompt for password

I need to create an automated script where I have to use sudo to switch to multiple user so the script stops and prompts for password, Is there a way I can provide the password in same command only? Remember that, I cannot disable the password settings of sudo as I dont have rights. (4 Replies)
Discussion started by: gauravgrover50
4 Replies

4. OS X (Apple)

Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password. So far I have: if ]; then sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2 if ; then echo "You entered an invalid password... (2 Replies)
Discussion started by: PatGmac
2 Replies

5. Shell Programming and Scripting

enter password at prompt during a script?

I'm using rsync with the "-e ssh" option so of course it asks for a password using a prompt. Is there a way to tell a script to expect a prompt, wait for it, and give a password when it arrives? There is a way to give rsync a password as part of its options using a file, but it only works with... (2 Replies)
Discussion started by: davidstvz
2 Replies

6. Shell Programming and Scripting

Shell Script to prompt customer for name etc

How do I create a shell script called 'custinfo' to prompt a customer to enter and display back the following: name, age, address, phone number, product, price range. Thanks (1 Reply)
Discussion started by: SQLScript
1 Replies

7. UNIX for Dummies Questions & Answers

Shell Script to prompt customer for name etc

reposting How do I create a shell script called 'custinfo' to prompt a customer to enter and display back the following: name, age, address, phone number, product, price range. Thanks (1 Reply)
Discussion started by: SQLScript
1 Replies

8. Shell Programming and Scripting

How to add password prompt between script ?

Hi Team, I need password prompt between this script .i want to need put password manually. Instead of adding password in script . Script pause till input password and resume again. #!/usr/bin/expect set ip spawn telnet $ip expect "login:" send "USR\r" expect "*assword*"... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

9. UNIX for Beginners Questions & Answers

Noob. shell script with prompt?

Hey Guys and Gals, Im a complete Noob to Unix. But recently have started working on a unix system for my PET/CT scanner. My scanner comes with a MOD drive for backup. I would like to back up to USB (its alot cheaper). But the only way to do so is by manually enterin the unix commands. Id like to... (13 Replies)
Discussion started by: TorresGXL
13 Replies

10. Shell Programming and Scripting

Expect script not expecting the password prompt

I have a script that does an SSH into a remote node. It should expect the prompt and send the password. #!/usr/bin/expect set user ; set pass ; spawn ssh $user@E-Internal expect { -re "RSA key fingerprint" {send "yes\r"} timeout... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy