Help in input file's in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in input file's in bash script
# 1  
Old 09-07-2016
Help in input file's in bash script

hello guys
i have bash script to open my routers with username and password
i made script but i have problem this script can/t read password from file
Code:
#!/bin/bash
router_file="ips"
passwd="password.txt"
for router in cat ;$router_file do
for pass  in cat ;$passwd; do
res=$(curl -m 1   "http://${router}" --user admin:${pass} )                                              
if echo $res | grep -i "stats"; then                                                                                       
echo "https://"$router >> log                                                                                                     
fi
done
done


Last edited by Corona688; 09-07-2016 at 05:46 PM..
# 2  
Old 09-07-2016
How are password.txt and router_file organized?

Please use code tags, the code button: Image not icode.
# 3  
Old 09-07-2016
Code:
cat password.txt
admin
adminis@@
admins@@@

Code:
cat router_file
192.168.1.1
192.168.1.2
192.168.1.3



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

Last edited by RudiC; 09-07-2016 at 07:25 PM.. Reason: Added CODE tags.
# 4  
Old 09-07-2016
Which password belongs with which router?
# 5  
Old 09-07-2016
first one for the first router and the sec for the sec router
# 6  
Old 09-07-2016
I have moved this thread to the subforum it belongs in. You shouldn't post code questions in the 'contact the moderators' forum.

If they're related, why are they different files? Then you have to do something like this:

Code:
exec 5<file1
exec 6<file2

while read ROUTER <&5 && read PASS <&6
do
        echo "do something with router $ROUTER password $PASS"
done

exec 5<&-
exec 6<&-

...when, with both in one file, you could have just done:

Code:
while read ROUTER PASS
do
        echo "do something with router $ROUTER password $PASS"
done <routerpass

# 7  
Old 09-07-2016
thanks alot my friend
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input redirection within bash script

Hi, when I try to redirect input and the command is described as a string within an array redirection does not work. why? #!/bin/bash dir=("tail < ./hello.txt") tail < ./hello.txt #works ${dir} #does not work (2 Replies)
Discussion started by: heinzel
2 Replies

2. Shell Programming and Scripting

While loop with input in a bash script

I have the following while loop that I put in a script, demo.sh: while read rna; do aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed) echo "$aawork" | sed 's/ //g' echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/*\(*\) \(.*\)/\2: \... (3 Replies)
Discussion started by: faizlo
3 Replies

3. Shell Programming and Scripting

Bash shell script with mandatory and optional input

Hello I would like to write a bash shell script which will need user to supply one variable which is mandatory and some other optional variables. If mandatory variable is not supplied by user, the script will exit. If optional values are not supplied by user, hard-coded value (in the script)... (3 Replies)
Discussion started by: atanubanerji
3 Replies

4. UNIX for Dummies Questions & Answers

Feed Input to a script running on bash

Hi Sir, I am just learning bash scripting and I came across a challenge. I need to input F11 to a script among many text inputs. For all the text inputs i did following. # sh test.sh < input.txt where input.txt contains all the text inputs in new lines. This worked fine until i... (1 Reply)
Discussion started by: gaurav kumar
1 Replies

5. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

6. Shell Programming and Scripting

Bash Script for parse input like option and value

I would create a bash script than parse like this: test.sh -p (protocol) -i (address) -d (directory) I need retrive the value after -p for example... understand??? I hope... thanks (6 Replies)
Discussion started by: ionral
6 Replies

7. Shell Programming and Scripting

Input file to bash script

Hi, I have this script Script.sh: #!/bin/sh sed 's,\,,g' input.dat > output .dat But i want to run it witb different files. So i want the input file as an input argument to the script, how could i do that. Running it like this: > Script.sh input.dat (2 Replies)
Discussion started by: Johanni
2 Replies

8. UNIX for Dummies Questions & Answers

Bash script to delete file input on command line

1) I wrote a script and gave the desired permissions using "chmod 755 scriptname". Now if i edit the script file, why do i need to set the permission again? Didn't i set the permission attribute.. or if i edit the file, does the inode number of file changes? 2) I am running my unix on a server... (1 Reply)
Discussion started by: animesharma
1 Replies

9. Shell Programming and Scripting

Separating list of input files (*.file) with a comma in bash script

Hi all, I'm trying to get a bash script working for a program (bowtie) which takes a list of input files (*.fastq) and assembles them to an output file (outfile.sam). All the .fastq files are in one folder in my home directory (~/infiles). The problem is that the 'bowtie' requires that... (7 Replies)
Discussion started by: TuAd
7 Replies

10. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies
Login or Register to Ask a Question