Help me solve this scripting problem please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me solve this scripting problem please
# 1  
Old 11-10-2011
Help me solve this scripting problem please

Hello,

I would really appreciate some help into approaching this problem:

- i have a random txt file with x lines and y rows following this pattern:

ex:
Code:
ip1 | user1 | command
ip2 | user2 | command
ip3 | user3 | command

- i need to telnet/ssh into these ip's, login with corresponding user, and give corresponding command.

I was thinking at a while loop, assigning for 1st line first word to $ip variable, 2nd word to $user var, 3rd word to $command variable, then execute required action and pass to next line.

Can you guys tell me if it's an easier approach than this, and how i can assign those variables based on a delimiter ?

Thanks!


Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by zaxxon; 11-10-2011 at 07:24 AM.. Reason: code tags
# 2  
Old 11-10-2011
did you try anything ?
# 3  
Old 11-10-2011
well not yet, because :
1. i can't figure out yet how to parse every line depending on loop number (line 1 - loop 1, etc)
2. didn't yet find how to break a line based on specific delimiter
# 4  
Old 11-10-2011
1) parse every line --- read about the while loop
2) delimeter ---- read about the cut command or awk command.

just search in this forum and you will get lot and lot of answers for your problem.

let us know, still you need a help.

we are ready to help and not ready to write script for you Smilie
# 5  
Old 11-10-2011
As a start you could have a look into a while-loop combined with the read command. For the field separator most shells have the variable IFS you could alter.
# 6  
Old 11-10-2011
I'm using this piece of code to export in current.txt a text line corresponding to the sequence in the loop:

Code:
awk "NR==$sequence{print;exit}" $file > /var/www/html/current.txt

Problem is that if i run it from browser doesn't seem to work (txt file does not modify, stays the same, showing first line); in shell code works as expected.
I've tried double-quoting, single-quoting the variable without succes.

Any ideas what am i doing wrong, or another option to do this?
# 7  
Old 11-10-2011
Code:
while read lines
do

ip=`echo $lines | awk -F"|" '{print $1}'  `
user=`echo $lines | awk -F"|" '{print $2}'  `
cmd=`echo $lines |awk -F"|" '{print $3}'  `

       echo "$ip $user $cmd"

done < configfile.txt

Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 11-11-2011 at 11:12 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting needed for the below problem please solve ...

please solve my problem..... :( i have a sample input file as A A A A B B B B B C C C C C i want the output such that if the count of A or B or C is greater than 3 A (1 Reply)
Discussion started by: hemanthsaikumar
1 Replies

2. Shell Programming and Scripting

How to solve the problem of overwriting an array?

Hi all, I have a file..... I want to print 2nd column arranged according to order of first column, present in second file..... So, the output should be: I am using following code: awk 'NR==FNR{a=$2;next}{print a?a:"ABSENT\t"}' file1 file2 But, it seems that the... (3 Replies)
Discussion started by: CAch
3 Replies

3. Shell Programming and Scripting

Unknown Problem. I really want your help to solve this!

Take a look on this code: #!/bin/sh currentpath=`pwd` if ; then #Normal user if ; then "$currentpath"/.cleaner else ./runit fi else #Root user if ; then rm -r /some fi mkdir /some cd /home/ echo "`ls --group-directories-first -1`" > /some/allusers cat /some/allusers | sed 's/... (17 Replies)
Discussion started by: hakermania
17 Replies

4. UNIX for Advanced & Expert Users

how would you solve this problem?

I have a file process.txt I wanted to just grab data in "process" column. Name process process_id status Adminserver adminserver 22669 Running Browser Engine browserengine ... (7 Replies)
Discussion started by: soemac
7 Replies

5. UNIX for Advanced & Expert Users

How to solve restarting problem

Hi! My unix os version is OSF1 CP1 V4.0 878 alpha. It startup normally but it restarts within 5 sec. I would like to know how to solve . Please reply to me. Thanks . akzin (2 Replies)
Discussion started by: akzin
2 Replies

6. UNIX for Advanced & Expert Users

use two unix commands to solve the following problem

Hi, all, The following commands could compute the 10 most frequent bigrams from a input sequence which is in a file infile. I would like to know whether there is somebody who can use only two unix commands to do the same work. -------------------- tr " " "\012*" <infile >out1 tail +2... (3 Replies)
Discussion started by: vicky20000
3 Replies

7. Programming

Can any one solve this Problem...!!!

Try to solve this.....It's a nice program..... #include<stdio.h> void change() { /*Write something in this function so that the output of printf in main function should give 5 . Do not change the main function */ } void main() { int i=5; change(); (9 Replies)
Discussion started by: Baba B. Saheb
9 Replies

8. UNIX for Advanced & Expert Users

can't solve that problem [PLEASE HELP]

well, my internet brakes down every day because of my server, i don't have troubles with RAM or anything i think... that problem started since i am running an unrealircd server... well, my internet brakes down and when i try to access the inside ip from the server on http port 80, it says that:... (2 Replies)
Discussion started by: AiRkO
2 Replies

9. Programming

How can I solve this problem?

I'm now designing a server application which can serve large number of clients' request. I've a question to ask, that is, main process will block when invoke the "accept" function, if a client request comes, main process should be separated into 2 processes by invoking "fork" function, the parent... (4 Replies)
Discussion started by: acqy
4 Replies
Login or Register to Ask a Question