Script does not read input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script does not read input file
# 1  
Old 03-29-2019
Script does not read input file

Hi everyone, I have problems with this script.
This script should check for a folder for each server in the list of the list.txt file.
The script only checks the first host, and then exits, why?

Code:
#!/bin/bash
file='/etc/list.txt'
while read line; do
echo $line
if ssh root@$line "stat /var > /dev/null 2>&1"; then
echo "File exists"
else
echo "File does not exist"
fi
done < $file

thank you very much for helping
n




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

And, while you are at it, please use MEANINGFUL THREAD TITLES too. What is a title like "help script" (your title until i changed it) to tell a potential reader, hmm? All people coming to the "Shell Scripting" forum need help with their scripts, don't you think so?

Last edited by bakunin; 03-29-2019 at 12:01 PM..
# 2  
Old 03-29-2019
Welcome to the forum.


That's because the ssh eats up all stdin from the redirected file. Try its -n option.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-29-2019
Thankuuuuuuuuuuuuuuuu very much !!!
Yessss, now It's working.
I've just only add the -n option to ssh command.

byezzzzzz
nashrik
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

Read xml file till script finds separation and run again for next input and so on

Hi All, I have one query, I managed to run script with user inputs through command line or with 1 file. But I need to read a txt file/xml file in which user can mention multiple sets of answers and script should run for each set till it reach the EOF. Thanks in advance for example, the file... (3 Replies)
Discussion started by: rv_champ
3 Replies

3. Shell Programming and Scripting

Read input in shell script

I want to write a script that read the input to variable. I want the input screen to have 2 lines, where the values already input will appear above the input line for example if I want to input the words below: like love live life The screen will display like this: 1. Before any input... (8 Replies)
Discussion started by: aydj
8 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

Read input file with in awk script not through command line

Hi All, Do we know how to read input file within awk script and send output toanother log file. All this needs to be in awk script, not in command line. I am running this awk through crontab. Cat my.awk #!/bin/awk -f function test(var){ some code} { } END { print"test code" } (5 Replies)
Discussion started by: random_thoughts
5 Replies

6. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

7. Shell Programming and Scripting

need shell or Perl script to read multiple input

I need shell 0r Perl script to read multiple input and do something and come out example: echo “ enter the host names separated by space “ read servers foreach @servers { do do something done} Here host names like host1 host2 host3 . . . . . . . so on Please help me... (8 Replies)
Discussion started by: sreedhargouda
8 Replies

8. Shell Programming and Scripting

Need a script that will read from 2 input file

Hi Everyone. I am new in this scripting world. I need to know about script that I can use on linux/sun operating systems. I have 2 input file. File 1: Its has an header information and then data in 2 different columns. File 2 : It has data in 9 different columns/ I need an script that... (3 Replies)
Discussion started by: syahmed
3 Replies

9. UNIX for Dummies Questions & Answers

read input file

echo "enter employee #:/c" read employee grep -w $employee /tmp/file.txt when it asked me employee #, i typed employee, worked fine. when it asked me employee #, i type ENTER, it just sit there. if someone type in NULL or ENTER key, i want to exit out. (2 Replies)
Discussion started by: tjmannonline
2 Replies

10. Shell Programming and Scripting

read a file as input and pass each line to another script

Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names. My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)
Discussion started by: sajjad02
0 Replies
Login or Register to Ask a Question