Loop with output to script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loop with output to script?
# 1  
Old 07-23-2013
Loop with output to script?

Hey guys,

I am VERY new to linux scripting and was wondering if you could help me with the following:

essentially the use case is the following...a service crashes and a script must be executed to rerun 3000 entries one at a time....your options are to do each of those manually, 1 at a time
or to write some type of loop to go through them
the question is really to read values from the file, send each line to the screen (to show which one you're on), and then send it to the script
I would like to write a loop script for this but am having some issues with my knowledge. I know this may be basic for some of you, but we all gotta start somewhere and im trying to learn.
# 2  
Old 07-23-2013
Hello,

if you can put some input code and as well output code too, it will be helpful for us to fulfil this requirement.



Thanks,
R. Singh
# 3  
Old 07-23-2013
Quote:
Originally Posted by wrnganswr
the question is really to read values from the file, send each line to the screen (to show which one you're on), and then send it to the script
You could do something like:
Code:
#!/bin/ksh

while read line
do
        printf "%s\n" "\"$line\"" | tee -a output.txt | tee /dev/tty | xargs ./yourscript.ksh

done < input.txt


Last edited by Yoda; 07-23-2013 at 04:38 PM..
This User Gave Thanks to Yoda For This Post:
# 4  
Old 07-23-2013
Why not
Code:
while read line
  do
    printf "%s\n" $line 
    /PATH/servicescript "$line"
  done < file

These 2 Users Gave Thanks to RudiC For This Post:
# 5  
Old 07-24-2013
Thanks guys

I would love to give more info, but that is all that I was given. Im trying my best to learn this amazing stuff myself. Dont really have the resources or people to help teach me from the bottom up. Used to be in the military and am trying to bulldoze my way back into the tech field. I have a good deal of the basics, so i need to move on to intermeidiate and advanced. Again thank you for your help!
# 6  
Old 07-24-2013
They have not given you the information you need to do your job. Or perhaps they expect you to explore and see what files are there and figure out what they want.
# 7  
Old 07-24-2013
agreed

I agree, But with my limited knowledge, i need to at least have a decent starting point imo. Im learning slowly but surely and i flipped my computer and put ubuntu on it and vboxed windows rather than the set i had which was flipped. This I think will help force me to learn a little more a little quickerSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script, For loop output to excel as columns

Hi, I have a shell script which analyses the log folder for a specific string and throws me the output. I have used for loop since it does this in multiple servers. Now I want to save the output in a excel in the below format. Can someone please help? The output which I get Server1 : count... (14 Replies)
Discussion started by: srilaxman
14 Replies

2. Shell Programming and Scripting

Expect Script - Not Seeing Output from While Loop

I know something simple is missing here, "log_user 1" is set . . . after this utility opens ${InFile} (handle? for IntInFile) it needs to look for something to appear in the file ${IntInFile} and then send it to the spawned process. Then I am locking the file ${IntInFile} and clearing it out -... (0 Replies)
Discussion started by: JuanMatteo
0 Replies

3. Shell Programming and Scripting

For loop output redirection

Hi All, i have below for loop of which i am trying to redirect output in a file: for i in `/usr/sbin/ifconfig -a | awk '/flags/ {print $1}' | grep -v lo | sed 's/://g'` do ifconfig $i dhcp status done >> /tmp/logfile but instead the output is appearing as stdout on screen rather than... (12 Replies)
Discussion started by: omkar.jadhav
12 Replies

4. Shell Programming and Scripting

Output in for loop (ksh)

Hi , I'm writing the for loop script in home directory and wanted to get the files from /etc/data directory. #!/bin/ksh file_nm="/etc/dat" for test_data in $file_nm/fln* do echo "$test_data" done the code is executing successfully , but in the output it is showing ... (6 Replies)
Discussion started by: smile689
6 Replies

5. Shell Programming and Scripting

while loop output

:wall:Hi I am a beginner to unix In a shell script i see the below code # set admin email so that you can get email ADMIN=someone@somewhere.com host=`hostname` date=`date` # set alert level 70% is default ALERT=70 df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print... (1 Reply)
Discussion started by: prabhu_kumar
1 Replies

6. UNIX for Dummies Questions & Answers

Writing a loop to manipulate a script and store it in multiple output files

I have a script where the the 9th line looks like this: $filename=sprintf("250.1chr%d.ped", $N); I want to modify this script 1000 times, changing 250.1chr%d.ped to 250.2chr%d.ped, 250.3chr%.ped.......and so on all the way to 250.1000chr%d.ped and store each output in files called ... (4 Replies)
Discussion started by: evelibertine
4 Replies

7. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

8. Shell Programming and Scripting

Reverse the output using for loop

Good morning!! Im trying to ge tthe output in this for loop to be reversed. #!/usr/bin/perl $i = 1; for($i != 0 ; $i < 11 ; $i++){ print "$i\n"; } Ive tried changing the i++ to i--, but it makes the outputted numbers different also. Thanks bigben (4 Replies)
Discussion started by: bigben1220
4 Replies

9. Shell Programming and Scripting

How to group the output of a loop

Hi Guys, This is based on my question previously posted. :) I have my shell script like this: #!/usr/bin/sh e_id=`sqlplus -s scott/tiger@DB<<eof SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF; select emp_id from employee; quit ... (1 Reply)
Discussion started by: alvingo
1 Replies

10. Shell Programming and Scripting

Sed subsitution on loop output in shell script

I have a forloop which checks a log for a set of 6 static IP addresses and each IP found is logged to a file which is then mailed to me. After the forloop I always have a text file that may contain up to 6 IP addresses or may contain 0. What I want to do is substitute the IP addresses (if any)... (2 Replies)
Discussion started by: Moxy
2 Replies
Login or Register to Ask a Question