Sponsored Content
Top Forums Shell Programming and Scripting How to find text in files without using the word itself but the assigned variable of it Post 302502494 by jenimesh19 on Tuesday 8th of March 2011 05:18:22 AM
Old 03-08-2011
@rdcwayx

when I used your correction to my script, it already went to the Invalid code.. blah blah.. then it terminated..But the username I entered is really in the login_users script..
what is the problem in this??

@chubler XL

That's what I'm thinking about.. but how can I do the sudo script??

These are the scripts related to the password recovery..

Here is the script to add accounts in the login_users

Code:
#============================================================
#  Script Name:   useradd
#  By:            JRG
#  Date:          March 5, 2011
#  Purpose:       A shell script used to add 
#          new user accounts to the login_users file
#  Command Line:  useradd
#===========================================================
trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
userfile=~/casestudies/login_users

  clear
  tput cup 1 4; echo "User Accounts Addition"
  tput cup 2 4; echo "======================="
  tput cup 4 4; echo "Username : "
  tput cup 5 4; echo "Password : "
  tput cup 6 4; echo "Answer the following questions in case of password recovery"
  tput cup 7 2; echo "A. What is your 5th favorite color? "
  tput cup 8 2; echo "B. What is your favorite food? "
  tput cup 9 2; echo "C. What is the name of your pet? "
  tput cup 10 2; echo "D. What is the middle name of your mother's maiden name? "
  tput cup 11 2; echo "E. What is the model number of your laptop/monitor? "
  
  tput cup 4 18; read username
  tput cup 5 18; read passwd
  tput cup 7 18; read A
  tput cup 8 18; read B
  tput cup 9 18; read C
  tput cup 10 18; read D
  tput cup 11 18; read E    
# Check to see if username is not blank before you
#write to disk
  if [ "$username" > "           " ] 
  then echo "$username:$passwd:$A:$B:$C:$D:$E" >> $userfile 
  fi
  tput cup 13 10; echo "(q)uit: "
  tput cup 13 10; read choice
  if [ "$choice" = "q" ]
    then 
      clear; exit   
  fi

Printing of lists
Code:
#============================================================
#  Script Name:   userlist
#  By:            JRG
#  Date:          March 5, 2011
#  Purpose:       Use awk to format colon-separated fields
#          in a flat file and display to the screen
#  Command Line:  userlist
#===========================================================
clear
  tput cup 2 4; echo "User List"
  tput cup 3 4; echo "========="
  tput cup 5 0; echo "P - Print User List"
  awk -F: '{printf "%-12s %-12s %s\t%s %s %10.10s %s\n", $2, $3, $4, $1, $5, $6, $7}' login_users

To select which one to do..
Code:
#============================================================
#  Script Name:   profile
#  By:            JRG
#  Date:          March 5, 2011
#  Purpose:       main menu 
#  Command Line:  profile
#===========================================================
profile=~/casestudies/users
loop=y
while [ "$loop" = y ]
do
  clear
  tput cup 3 12; echo "  Welcome to your profile  "
  tput cup 4 12; echo "==========================="
  tput cup 6 9; echo "What do you want to do? "
  tput cup 7 9; echo "C - create an account"
  tput cup 8 9; echo "L - Login"
  tput cup 9 9; echo "F - Forgot password"
  tput cup 10 9; echo "Q - Quit"
   read choice || continue
     case $choice in
       [Cc]) ./useradd;;
       [Ll]) ./login1 ;;
       [Ff]) ./forgotpass;;
       [Qq]) exit ;;
        *) tput cup 13 4; echo "Invalid Code"; read choice ;;
     esac
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What does $? mean when assigned to a variable?

If i write this statement in a Korn Shell script RCODE=$? what possibly does it eman? (3 Replies)
Discussion started by: ranjita.c
3 Replies

2. Shell Programming and Scripting

Check if a variable has a value assigned?

Hi, I want to check if a variable has a value assigned to it or not. I can do following - cat $Var > File1 if then echo "$Var has value" else echo "$Var is null" fi But I have to check for 3 Variables and I want to wrap it up in couple of unix statements. Any... (3 Replies)
Discussion started by: sumeet
3 Replies

3. Shell Programming and Scripting

How to find and print the last word of each line from a text file

Can any one help us in finding the the last word of each line from a text file and print it. eg: 1st --> aaa bbbb cccc dddd eeee ffff ee 2nd --> aab ered er fdf ere ww ww f the o/p should be a below. ee f (1 Reply)
Discussion started by: naveen_sangam
1 Replies

4. Solaris

Command files when the output is assigned to a variable

Hi, i'm posting this in the Solaris forum although maybe it should be better in the General unix forum, I'm formatting an output witht he following command: crontab -l | grep GBOUAT8 | grep UTP | grep -i stop | sed 's/\\//' 08 2 * * 2-6 /apps/sum_glob/gbo_uat/sparse/bin/dmg_cronlaunch -ENVI... (2 Replies)
Discussion started by: Cvg
2 Replies

5. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

6. UNIX for Dummies Questions & Answers

How do you check if a variable has been assigned?

I am trying to check whether a variable has been assigned on the command line or not. Here is what I did: #!/usr/bin/bash if( $variable == '\0') { print "variable was not assigned" exit } else NF = 2 {print $1, ""} exit fi awk -f question1.awk variable = 58 letters.txt. So... (3 Replies)
Discussion started by: Fred63528
3 Replies

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. Shell Programming and Scripting

How to find the number of occurence of particular word from a text file?

example: i have the following text file... i am very tired. i am busy i am hungry i have to find the number of occurence of a particular word 'am' from the text file.. can any one give the shell script for it (34 Replies)
Discussion started by: sheela
34 Replies

9. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

10. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies
All times are GMT -4. The time now is 02:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy