Problem in taking input Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in taking input Shell script
# 1  
Old 01-17-2017
Question Problem in taking input Shell script

I was writing a shell script, where i need to run a command through script and then take input from user and later terminate it. i am not sure how to take input in a proper format immediately after a command.

example: below command line is used to import some data in to database (LDAP)
Code:
ldapmodify -h "localhost" -p "14389" -D "cn=Directory Manager" -j "$dmpass"

after entering this command it expects the input from user in below format

Code:
*****************************************************
dn: uid=$b, ou=People,dc=p3chem,dc=net
changetype: modify
replace: BusinessCategory
BusinessCategory: Shipped  
******************************************************

above LDIF file changes the status of particular user in DataStore (LDAP).

now, my doubt is how to write a script in such a way that it uses the command :
Code:
ldapmodify -h "localhost" -p "14389" -D "cn=Directory Manager" -j "$dmpass"

to import LDIF file and then take the input in above format...

If i give the above 4 lines in the same format just after the Ldapmodify command it throws error

Last edited by rbatte1; 01-17-2017 at 01:06 PM.. Reason: Added CODE tags
# 2  
Old 01-18-2017
Welcome to the forum.

Unfortunately your request is not clear. Do you want the user sitting in front of the terminal to key in that unusually stritctly formatted, voluminous, and error prone 6 line data record, or do you need to supply that structured text to ldapmodify? Does ldapmodify read from stdin?

And, please use CODE tags as required by forum rules!
# 3  
Old 01-18-2017
Hi Rudic,

Thanks for your quick response.

I want the user to provide only User ID in the start, later it should take that value in variable.

FYI, ldapmodify command expects an input to be supplied in below form

Code:
dn: uid=$b, ou=People,dc=p3chem,dc=net  //$b is the value which user will input
changetype: modify
replace: BusinessCategory
BusinessCategory: Shipped

here if you see in the first line it has something called as "uid", there i want to have the User ID (uid) value inputted by the user, rest things remains the same.

now my doubt is how to supply above 4 lines as input to ldapmodify command.

This will be more clear by looking at the script which i have developed till now, and stuck at that place.

code:
Code:
==================================================

#!/bin/bash

#script is for re-enabling the user in CPass

FILE=/opt/oracle/scripts/a.out

echo "
********************************************************
Enter one among the below options                      *
                                                       *
1. To check the current status of user in CPass LDAP   *
2. Change the Business category of user to \`Shipped\` *
3. Add user to CPassAllowed group                      *
4. Exit from the script                                *
********************************************************
"
echo -n "please enter a value: "
read n

case $n in

1) echo -n "Please enter the User ID (uid) of user: "
   read a
   ldapsearch -h localhost -p 4545 -D "cn=Directory Manager" -j "$dmpass" -b "ou=People,dc=p3Chem,dc=net" -s sub "(uid=$a)" "businessCategory" | tail -1 > $FILE

   if [[ -s $FILE ]]; then
        echo "`ldapsearch -h localhost -p 4545 -D "cn=Directory Manager" -j "$dmpass" -b "ou=People,dc=p3Chem,dc=net" -s sub "(uid=$a)" "businessCategory" | tail -1`"
        exit
   else
        echo "User ID which you have entered doesnot exist in PKI lDAP"
        exit
   fi
   ;;
2) echo -n "Please enter the user ID whose Business category needs to be changed: "
   read b
   ldapsearch -h localhost -p 4545 -D "cn=Directory Manager" -j "$dmpass" -b "ou=People,dc=p3Chem,dc=net" -s sub "(uid=$b)" "businessCategory" | tail -1 > $FILE

   if [[ -s $FILE ]]; then
        echo "Changing the Business Category of user $b...please wait"
		ldapmodify -h "localhost" -p "4545" -D "cn=Directory Manager" -j "$dmpass"
		dn: uid=$b, ou=People,dc=p3chem,dc=net
		changetype: modify
		replace: BusinessCategory
		BusinessCategory: Shipped
		sleep 5
		echo "\n Current status of user in PKI LDAP is `ldapsearch -h localhost -p 4545 -D "cn=Directory Manager" -j "$dmpass" -b "ou=People,dc=p3Chem,dc=net" -s sub "(uid=$b)" "businessCategory" | tail -1`"
		
        exit
        else
                echo "User ID which you have entered doesnot exist in PKI lDAP"
        exit
   fi
   ;;
*) echo "No option selected"
   ;;
esac

####################################

Thanks,

Mridul Utkarsh

---------- Post updated at 08:36 AM ---------- Previous update was at 08:33 AM ----------

In the above code, case statement (2) - if part has the logic

Code:
if [[ -s $FILE ]]; then
echo "Changing the Business Category of user $b...please wait"
ldapmodify -h "localhost" -p "4545" -D "cn=Directory Manager" -j "$dmpass"

After this it fails to take input.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 01-18-2017 at 09:37 AM.. Reason: Added CODE tags.
# 4  
Old 01-18-2017
Please make sure to comply to the the forum rules, in particular: use code tags, and post in an adequate forum, so moderators don't need to clean up after you.

Rg. your problem: the other invocations of ldapmodify seem to be fed input data by passing parameter values; why doesn't that work for the one in question?
If no, can you specify an input file where it searches for data?
For your above setup, did you consider using a bash "here document" (c.f. man bash)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to delete files older than x days and also taking an input for multiple paths

Hi , I am a newbie!!! I want to develop a script for deleting files older than x days from multiple paths. Now I could reach upto this piece of code which deletes files older than x days from a particular path. How do I enhance it to have an input from a .txt file or a .dat file? For eg:... (12 Replies)
Discussion started by: jhilmil
12 Replies

2. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

3. Shell Programming and Scripting

Taking one input at a time

Legends, Please help me to come out of the below Bermuda triangle. I have four inputs in a shell script: A B C D Now, If A is passed by user then, B C D will be ignored. If C is passed by user, then A B D will be ignored. Regards, Sandy (11 Replies)
Discussion started by: sdosanjh
11 Replies

4. Shell Programming and Scripting

Problem while taking input from User

Hi All, I am facing a problem while taking input from user in Shell Script. Basically , I want to read a file line by line. And I want to remove certain lines of that file.But before removing those lines , I need to ask the user whether user wants to remove the lines. If user inputs "Yes" , the... (3 Replies)
Discussion started by: swapnil.nawale
3 Replies

5. Shell Programming and Scripting

problem with Regular expression as input in shell script

Hi, I have script which will take a string as input and search in a file. But when I want to search a pattern which has special characters script is ignoring it. For example: I want to search a pattern "\.tumblr\.com". shell script is removing \ (backslah) and trying to search... (7 Replies)
Discussion started by: Anjan1
7 Replies

6. UNIX for Dummies Questions & Answers

Problem with Input Parameters using Shell Script

i have this basic code that accepts for two input one for the source file and the other is for the target directory. basically it is a simple copy command. the problem is at the end of the execution the second parameter string was passed to first parameter and it displays a message like: cp:... (3 Replies)
Discussion started by: wtolentino
3 Replies

7. Shell Programming and Scripting

<AIX>Problem in purge script, taking very very long time to complete 18.30hrs

Hi, I have here a script which is used to purge older files/directories based on defined purge period. The script consists of 45 find commands, where each command will need to traverse through more than a million directories. Therefore a single find command executes around 22-25 mins... (7 Replies)
Discussion started by: sravicha
7 Replies

8. Shell Programming and Scripting

Problem taking input from file with for loop

I am trying to take input from a file and direct it into a bash script. This script is meant to be a foreach loop. I would like the script to process each item in the list one by one and direct the output to a file. # cat 1loop #!/bin/bash # this 2>&1 to redirect STDERR & STDOUT to file... (4 Replies)
Discussion started by: bash_in_my_head
4 Replies

9. Shell Programming and Scripting

put an interactive script in background after taking input

i am trying to find a way to put an interactive script in the background after taking input from the user a few test lines i was trying: date echo "Enter location" LOCATION= read LOCATION sleep 100 sleep 200 date for this small example i want the script to as the user for the... (7 Replies)
Discussion started by: epsilonaurigae
7 Replies

10. Shell Programming and Scripting

Shell script is taking more than 3 hrs to execute

Hi I am doing a process of converting all the values of key column into a row, for eg Key col1 col2 1 1 1 1 2 1 1 1 3 1 3 1 2 ... (2 Replies)
Discussion started by: nvuradi
2 Replies
Login or Register to Ask a Question