How to take input from the user from the command line and execute commands basedon that?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to take input from the user from the command line and execute commands basedon that?
# 8  
Old 06-01-2012
Please post the whole script content and only it, i.e. without broken comments or whatever.

In any case, this is bogus:
Code:
$userid=$1

Should be
Code:
userid=$1

# 9  
Old 06-01-2012
Sorry I am giving the entire script here.It is for Build process automation.I have red color for the troubling part
Code:
#!/usr/bin/bash
 
#checking for the directories and creating them accordingly
if [ -d /export/home/vomappservers/spa ]; then
 echo "directory already exist"
else 
 mkdir -p /export/home/vomappservers/spa
fi
#link to /export/home/vomappservers/spa from /spa
ln -s /export/home/vomappservers/spa spa
if [ -d /export/home/vomappservers/spa/common/5.0 ]; then
 echo "directory already exist"
else 
 mkdir -p /export/home/vomappservers/spa/common/5.0
fi
 
if [ -d /export/home/vomappservers/spa/common/scripts ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/spa/common/scripts
fi
if [ -d /export/home/vomappservers/spa/tools ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/spa/tools
fi
 
if [ -d /export/home/vomappservers/spa/scm5.0/SCCS ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/spa/scm5.0/SCCS
fi
if [ -d /export/home/vomappservers/spa/scm5.0/checkpt ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/spa/scm5.0/checkpt
fi
echo "directories created"
 
#populating the Scripts directory from SVN
cd /export/home/vomappservers/spa/common
echo "starting checkout scripts directory"
echo "Please enter your urerid  followed by [ENTER]:"
userid=$1
read userid
if [ "$userid" = "$user1" ] || [ "$userid" = "$user2" ] || [ "$userid" = "user3" ] || [ "$userid" = "user4" ]
then
svn checkout  --username $1 https://scm-coconet.capgemini.com/svn/repos/vomsource/sourcecode/vomappaservers/spa/common/scripts
echo "completed https://scm-coconet.capgemini.com/svn/repos/vomsource/sourcecode/vomappaservers/spa/common/scripts directory"
else
echo "invalid id please provide the valide userid"
fi
 
 
chmod 755 /export/home/vomappservers/spa/common/scripts
 
#populating the tools directory from SVN
cd /export/home/vomappservers/spa
echo"started checkout tools directory"
userid=$1
read userid
if [ "$userid" = "$user1" ] || [ "$userid" = "$user2" ] || [ "$userid" = "user3" ] || [ "$userid" = "user4" ]
then
svn checkout  --username $1 https://scm-coconet.capgemini.com/svn/repos/vomsource/sourcecode/vomappservers/spa/tools
echo "completed checkout https://scm-coconet.capgemini.com/svn/repos/vomsource/sourcecode/vomappservers/spa/tools directory"
else
echo "invalid user id .please provide the valid id" 
 
 
chmod 755 /export/home/vomappservers/spa/tools
 
 
#exporting the.bashrc file from the SVN
cd /export/home/vomappservers/spa
echo "started exporting .bashrc file"
userid=$1
read userid
if [ "$userid" = "$user1" ] || [ "$userid" = "$user2" ] || [ "$userid" = "user3" ] || [ "$userid" = "user4" ]
then
svn export --username $1 https://scm-coconet.capgemini.com/sv...rs/spa/.bashrc
else
echo "It is an invalid id.please enter valide userid."
 
echo "completed exporting .bashrc file"
 
 
chmod 755 /export/home/vomappservers/spa/.bashrc
#Creating the softlink to mkspadirs to mkspadirs.pl
cd /export/home/vomappservers/spa/tools
ln -s ./mkspadirs.pl mkspadirs
#creating the symolink link to /spa/common/scripts from scripts.
cd /export/home/vomappservers/spa
ln -s  /export/home/vomappservers/spa/common/scripts scripts
 
#Exporting the .SPADEF from the SVN
cd /export/home/vomappservers/spa
echo "started exporting .SPADEF file"
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv...rs/spa/.SPADEF
echo "completed exporting .SPADEF file"
 
chmod 755 /export/home/vomappservers/spa/.SPADEF
if [ -d /export/home/vomappservers/spa/common/scripts/include ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/spa/common/scripts/include
fi
#Exporting machdefs.pl file from the SVN
cd /export/home/vomappservers/spa/common/scripts/include
echo "started exporting machdefs.pl"
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv...de/machdefs.pl
echo "complete exporting machdefs.pl file"
chmod 755 /export/home/vomappservers/spa/common/scripts/include/machdefs.pl
#Executing the mkspadirs script
cd /export/home/vomappservers/spa/common
./mkspadirs -d -5.0
echo $?
if [ "$?" = "0" ]
then
echo "mkspadirs executed successfully"
else
echo "There is an error in execution of mkspadirs script"
fi
#Executing the mkwk script
./mkwk 
echo $?
if [ "$?" = "0" ]
then
echo "mkmk script executed successfully"
else
echo "There is an error in execution of mkmk script"
fi
#Export of sa0_genfile,sa0_genflags,sa0_genlibs,sa0_genver_debug from SVN
cd /export/home/vomappservers/spa/5.0
echo "export of sa0_genfile started"
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv....0/sa0_genfile
echo "export of sa0_genfile completed"
echo "export of sa0_genflags started"
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv...0/sa0_genflags
echo "export of sa0_genflags completed"
echo "export of sa0_genlibs started"
chmod 755 /export/home/vomappservers/spa/5.0/*
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv....0/sa0_genlibs
echo "export of sa0_genlibs completed"
echo "export of sa0_genver_debug started"
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv...0_genver_debug
echo "export of sa0_genver_debug completed"
#creating the symbolic to sa0_genfile from genfile
cd /export/home/vomappservers/spa/common
ln -s sa0_genfile genfile
#Populating the include and scripts directory from the SVN
cd /export/home/vomappservers/spa/5.0
userid=$1
svn checkout  --username $1 https://scm-coconet.capgemini.com/sv...pa/5.0/include
svn checkout  --username $1 https://scm-coconet.capgemini.com/sv...pa/5.0/scripts
chmod 755 /export/home/vomappservers/spa/5.0/*
#populating the hps.benv file from the SVN
cd /seer/nes/nete
userid=$1
svn export --username $1 https://scm-coconet.capgemini.com/sv...e/hps.benv(can be moved to admin stuff As per the C++tem suggestion since it involves creation of directoy from root)
#Symbolic link to perl(can be done as a Admin)
ln -s /usr/bin /usr/local/bin
#Creating the Symbolic link
cd /export/home/vomappservers/spa/tools 
ln -s mkspadirs.pl mkspadirs
#Executing the spaenv script.
cd /export/home/vomappservers/spa
./spaenv
echo $?
if [ "$?" = "0" ]
then
echo "spaenv executed successfully"
else
echo "There is an error in execution of spaenv script"
fi
#Checking for the symbolic proper or not in /spa/5.0 module befor the make or build script execution.
cd /export/home/vomappservers/spa/5.0
ln -s machdefs.pl AUX_MACHINE_DEFINITION
ln -s /export/home/vomappservers/spa/common/5.0/bin bin
ln -s /export/home/vomappservers/spa/common/5.0/data data
ln -s /export/home/vomappservers/spa/common/5.0/filetran filetran
ln -s /export/home/vomappservers/spa/common/5.0/lib lib
ln -s /export/home/vomappservers/spa/common/5.0/scripts scripts
ln -s /export/home/vomappservers/spa/common/5.0/tmp tmp
ln -s sa0_genfile genfile
ln -s sa0_genflags genflags
ln -s sa0_genlibs genlibs
ln -s sa0_genver_release genver
ln -s /export/home/vomappservers/spa/tools/gen2.pl gen
ln -s /export/home/vomappservers/spa/common/5.0/obj obj
 
echo "Please enter M for make file and B for make and build file, followed by [ENTER]:"
read option_mb
if [[ "$option_mb" == "M" ]]
then
 
#command for make file
/export/home/vomappservers/spa/5.0/gen -c
else
if [[ "$option_mb" == "B" ]]
then
#command for make and build file
/export/home/vomappservers/spa/5.0/gen clean all
else
echo "Enter correct option"
fi
fi
echo "selected process is  completed"
 
#Sessmgr modification 3rd point directories creation.
if [ -d /export/home/vomappservers/sessmgr/4.0/release ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/sessmgr/4.0/release
fi
 
#Creating the symbolic link for SESSLIB 
if [ -d /export/home/vomappservers/spa/5.0/build/lib ]; then
 echo directory already exist
else 
 mkdir -p /export/home/vomappservers/spa/5.0/build/lib
fi
cd /export/home/vomappservers/spa/5.0/build/lib
ln -s /export/home/vomappservers/security/sessmgr/4.0/release SESSLIB
 
echo "Build process for SPA module is completed"

# 10  
Old 06-01-2012
You didn't correct the issue I reported in post #3
# 11  
Old 06-01-2012
Could you please let me know how can I change that to two users like you have suggested?I have made followin changes to the code to test whether at least for one userid it is allowing or not.
Code:
 #populating the Scripts directory from SVN
    41  cd /export/home/vomappservers/spa/common
    42  pwd
    43  echo "starting checkout scripts directory"
    44  echo "Please enter your urerid  followed by [ENTER]:"
    45  userid=$1
    46  read userid
    47  if [ "$userid" = "$mvaddadi" ]
    48  then
    49  svn checkout  --username $1 https://scm-coconet.capgemini.com/sv...common/scripts
    50  echo "completed https://scm-coconet.capgemini.com/sv...common/scripts directory"
    51  else
    52  echo "invalid id please provide the valid userid"
    53  fi


i have just tried a dry run of the script it has thrown folloing error:
Code:
$ ./testscript.sh
directory already exist
ln: cannot create spa/spa: File exists
directory already exist
directory already exist
directory already exist
directory already exist
directory already exist
directories created
/export/home/vomappservers/spa/common
starting checkout scripts directory
Please enter your urerid  followed by [ENTER]:
mvaddadi
invalid id please provide the valide userid
./testscript.sh: line 60: echostarted checkout tools directory: command not found

# 12  
Old 06-01-2012
Code:
if [ "$userid" = "mvaddadi" ]

This User Gave Thanks to jlliagre For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Execute a command with root user

i m logged in with user1 id. i wish to execute the below as root user for which i tried several commands but all of them fail. sudo 'cat /tmp/tmp.file >>/etc/logger' Password: sudo: cat /tmp/tmp.file >>/etc/logger: command not found sudo cat /tmp/tmp.file >>/etc/logger bash:... (5 Replies)
Discussion started by: mohtashims
5 Replies

3. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

4. Shell Programming and Scripting

Script for login to servers with user name and password and execute commands

I am having the 15 servers which need to do the monitoring Hi I need a shell script, By which i can log in to multiple servers and execute the commands.. I need to specify the username and password in the scripts. Please help me to write the script so that it can login with username and... (5 Replies)
Discussion started by: nandan8a
5 Replies

5. Shell Programming and Scripting

Command line user input validation

Hi guys, I have a piece of snippet below which asks the user to input some numbers if isDatasubEnabled && isReconEnabled; then echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit" elif isDatasubEnabled &&... (4 Replies)
Discussion started by: pyscho
4 Replies

6. Shell Programming and Scripting

Command to execute commands one after other

I am writng a script in which there is an installation file.The installer runs good. But after the installer command there are some files and commands which are based on those installed files. Now problem is the commands get executed before the installer is totally installed. So is there any... (5 Replies)
Discussion started by: sriki32
5 Replies

7. Shell Programming and Scripting

Execute commands to specific folder from input file

Hi, I have one text file input.txt, which has folders path as follows: /home/user/automate/abc /home/user/automate/abc/xyz /home/user/automate/test /home/user/automate/test2 /home/user/automate/test2/abc/Main In those folders i have .svn folder. 1) First i want to remove .svn like rm... (5 Replies)
Discussion started by: dragon.1431
5 Replies

8. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh URL="www.google.com" VBURL="10.5.2.211" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

9. Shell Programming and Scripting

How to restrict the number of commands user can execute

Hi all, Is there a way to prevent users from being able to execute commands less a select few? For instance, I wish to allow the user to be only able to execute 1 command, which is exec a.sh. He should not be able to do simple stuff such as ls, cd, rm, cat, etc. Can this be achieved? ... (1 Reply)
Discussion started by: rockysfr
1 Replies

10. Shell Programming and Scripting

Can Xargs execute multiple commands of evry input file

Hello , I am trying to print the footer of evry file in the given directory with xargs command like follows ls -1 | xargs -I {} gzcat {} | tail -1 now problem with this is only last file foooter is getting printed as " | tail -1 " is getting executed for the last file. I know this can... (4 Replies)
Discussion started by: nilesrex
4 Replies
Login or Register to Ask a Question