Script to run command against multiple specific value in one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to run command against multiple specific value in one file
# 8  
Old 08-11-2011
Quote:
Originally Posted by itkamaraj
save the code in a normal file and assign execute permission and execute it
any guide to do this?
# 9  
Old 08-11-2011
1) create a normal file and put the below contents

Code:
 
#!/bin/bash
while read line;
do
usrid=`echo $line | awk -F"/" '{print $2}'`
echo "Executing for the $usrid"
echo "Command : ./ns-inactivate.pl -h mldap1 -p 389 -D \"cn=Directory Manager\" -w admin123 \-I \"uid=$usrid,ou=People,o=solarisX.com.ru,o=isp\""
# ./ns-inactivate.pl -h mldap1 -p 389 -D "cn=Directory Manager" -w admin123 \-I "uid=$usrid,ou=People,o=solarisX.com.ru,o=isp"
done < 30days.out

and save it as myscript.sh

2) execute the below command

Code:
 
chmod 777 myscript.sh

3) make sure you have the 30days.out file is present in the same directory.

4) execute the script

Code:
 
./myscript.sh

5) check the output and make sure is that the same command you want to execute.

6) after the confirmation, remove the # from the 7th line and execute it once again
# 10  
Old 08-11-2011
Quote:
Originally Posted by itkamaraj
execute the below code and make sure the command is correct.

once it is correct, remove the comment #

Code:
 
while read line;
do
usrid=`echo $line | awk -F"/" '{print $2}'`
echo "Executing for the $usrid"
echo "Command : ./ns-inactivate.pl -h mldap1 -p 389 -D \"cn=Directory Manager\" -w admin123 \-I \"uid=$usrid,ou=People,o=solarisX.com.ru,o=isp\""
# ./ns-inactivate.pl -h mldap1 -p 389 -D "cn=Directory Manager" -w admin123 \-I "uid=$usrid,ou=People,o=solarisX.com.ru,o=isp"
done < 30days.out

Hi,

How the same script can be apply to file that contain data like this,

Code:
more test3.out

12
2423love
2test10
2test11
2test13
2test15
5281kjs
5494jen
855hg1
936mlk
A1624
A212121
A705236
AAITCM
ACERLITE

and this one

Code:
more test4.out

   1 -ujmr@x.com
   1 06537my@x.com
   1 123ahfai@x.com
   1 1capitol@styx.com
   1 1mercury@a.com
   1 31337@yx.com
   1 324css@seax.com
   1 3dotcomp@stre.com
   1 46sdsl@hx.com
   1 4si@x.com
   1 5503@myx.com
   1 6_sense@styx.com

# 11  
Old 08-16-2011
nevermind the questions i already have an idea how to create new script base on that files.
# 12  
Old 08-23-2011
Quote:
Originally Posted by itkamaraj
execute the below code and make sure the command is correct.

once it is correct, remove the comment #

Code:
 
while read line;
do
usrid=`echo $line | awk -F"/" '{print $2}'`
echo "Executing for the $usrid"
echo "Command : ./ns-inactivate.pl -h mldap1 -p 389 -D \"cn=Directory Manager\" -w admin123 \-I \"uid=$usrid,ou=People,o=solarisX.com.ru,o=isp\""
# ./ns-inactivate.pl -h mldap1 -p 389 -D "cn=Directory Manager" -w admin123 \-I "uid=$usrid,ou=People,o=solarisX.com.ru,o=isp"
done < 30days.out

this script will run ns-inactivate.pl with userid including the domain,
Code:
-bash-3.00# ./tmnetscript.sh
Executing for the tmnet00003@solarisX.com.ru
Command : ./ns-inactivate.pl -h mldap1 -p 389 -D "cn=Directory Manager" -w admin123 \-I "uid=tmnet00003@solarisX.com.ru,ou=People,o=solarisX.com.ru,o=isp"

how can I change the script so that it will run against userid only,
e.g
Code:
-bash-3.00# ./tmnetscript.sh
Executing for the tmnet00003@solarisX.com.ru
Command : ./ns-inactivate.pl -h mldap1 -p 389 -D "cn=Directory Manager" -w admin123 \-I "uid=tmnet00003,ou=People,o=solarisX.com.ru,o=isp"

# 13  
Old 08-26-2011
nevermind, found it myself. thx
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Script to run #groups command on list in a file

I have to provide a listing of all usernames and group assignments on Linux servers running SLES 12 SP 3. I am trying to automate this via a #for loop. It is not doing as desired and could use a little assistance. Here is the code: #!/bin/bash for uname in 'cat $(hostname)_unlist.txt' do... (8 Replies)
Discussion started by: Kentlee65
8 Replies

3. Shell Programming and Scripting

Script to read file and run multiple jobs

I have a txt file line1 line2 line3 $!/bin/sh cat /tmp/lus.txt | while read line do esxcli storage vmfs unmap -u $lin -n 4000 done this works but does in one line at a time. how do I do all lines at once simutaeously? Please use CODE tags as required by forum rules! (4 Replies)
Discussion started by: tdubb123
4 Replies

4. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

5. Shell Programming and Scripting

help needed with shell script to append to the end of a specific line in a file on multiple servers

Hi Folks, I was given a task to append three IP's at the end of a specific (and unique) line within a file on multiple servers. I was not able to do that with the help of a script. All I could was: for i in server1 server2 server3 server4 do ssh $i done I know 'sed' could be used to... (5 Replies)
Discussion started by: momin
5 Replies

6. Shell Programming and Scripting

Run .command at specific times

Okay so I've got a command to start my java server up, but I want it to start at say 8:00AM and then stop at 11:00PM. In order to stop it I have to type stop and press enter in the terminal. I've been trying to get this to work and I'm having no luck. Here's my command: #!/bin/bash cd "`dirname... (2 Replies)
Discussion started by: JustChillin1414
2 Replies

7. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

Hello I am trying to run a python program using shell script, which takes a single argument from a file. This file has one entry per line : 1aaa 2bbb 3ccc 4ddd 5eee ... ... ... My shell script runs the program, only for the last entry : #!/bin/sh IFS=$'\n' for line in $(cat... (2 Replies)
Discussion started by: ad23
2 Replies

8. Shell Programming and Scripting

Run perl script with multiple file arguments

Hello everyone, I have two types of files in a directory: *.txt *.info I have a perl script that uses these two files as arguments, and produces a result file: perl myScript.pl abc.txt abc.xml How can I run this script (in a "for" loop , looping through both types of files)... (4 Replies)
Discussion started by: ad23
4 Replies

9. UNIX for Dummies Questions & Answers

Run Command in Specific Time ...

Guy's I want to make script to run this command solevel every Saturday at 8:00 clock exactly . Can you please help me and teach me how to do this ... (9 Replies)
Discussion started by: IT Helper
9 Replies

10. UNIX for Dummies Questions & Answers

Command to run multiple commands from a file.

I need a command, which could run mutliple commands from a file. Let's say, I have mv fileA1 fileB1 mv fileA2 fileB2 ..... mv fileA20 fileB20 I put these commands in a file, then I need a command to run the file as a whole so that I don't need to type 20 times... Anyone tell me how to... (8 Replies)
Discussion started by: kaixinsjtu
8 Replies
Login or Register to Ask a Question