Tagged Questions
2
votes
1answer
34 views
grep for files through another list of files
I'm trying to find if some java classes are called in a list of script files that are actually being called in a scheduler.
while read j; do
while read b; do
#Read through job files
...
1
vote
4answers
75 views
Why is this bash while loop infinite?
This is my first time making a bash script...
I'm trying to make a bash script that will delete the oldest file in a directory until said directory is under a certain size. I want the while look to ...
0
votes
1answer
44 views
Source file (containing list of variables) to be run in bash loop?
I've got a file containing 2 variables, start and end that I want invoked in a for loop of a bash script but I can't seem to get the result I want
outputfile2.text
START=26 ; END=47
START=48 ; ...
0
votes
1answer
25 views
Reading Multiple files in a while loop in bash, where one file is multicolumn
There are many posts one how to read from more than one file in bash.
paste provides one solution, and other solutions exist as well.
However, what I have not found is the following.
If one has a 2 ...
0
votes
2answers
33 views
Pipes with while loops within Parentheses
I am going to ask about a structure about pipes with while loops within parentheses.
Imagine I have a script like this:
#!/bin/bash
<FirstCommand> | (while read var1; do out=`echo $var1 | ...
1
vote
1answer
35 views
Bash forked for loop with while loop control
I have a for loop that will cycle through all the files in a directory. I want to run a process on each file (in this example echo file name and sleep 5). However I want to be able to run this 5 files ...
0
votes
0answers
32 views
linux bash vs ./ loop error
I have a script that has a loop with this basic code:
while read -r line
do
...
done < <(rsync --list-only --rsync-path='sudo rsync' [sftploginandpath]);
It works great when I test it, ...
2
votes
1answer
19 views
Output $(rpm -Va) to array with spaces intact
I'm attempting to put the output from rpm -Va into an array so that I can then run multiple checks against the results. I would very much like to be able to have each output line from the rpm command ...
0
votes
1answer
36 views
BASH Check if [process] is running, recheck every hour
I have shred running in the background on 16 drives. I would like to have a bash script that checks the process pidof shred every hour. If the process doesn't show, then echo "Shredding Completed... ...
0
votes
1answer
28 views
linux bash array contains no data after while block [duplicate]
I have the code that reads partitions and puts elements in array, but after block while I have no more elements in. The last echo length ${#availableb[*]} returns 0 instead 3 because I have 3 ...
0
votes
2answers
28 views
Check if output file is generated and populated with expected logs - BASH
A process (in background) should create a file (e.g. result.txt) and populate it with 5 log lines.
I need to check: 1) if the file exists and 2) checks if all the logs (5 lines) are stored
If these ...
0
votes
1answer
19 views
How to break infinite loop in this script
I am doing something interesting with bash
I wrote script below:
#!/bin/bash
while :
do
if [ -s /tmp/file.txt ]; then
for line in $(cat /tmp/file.txt)
do
echo $line
...
-1
votes
4answers
47 views
Bash while read : output issue
Updated :
Initial issue :
Having a while read loop printing every line that is read
Answer : Put a done <<< "$var"
Subsequent issue :
I may need some explanations about some SHELL code :
I ...
1
vote
0answers
39 views
curl to bing web site in bash from list
I want to get host of a web site like filehippo.com:
What I tried is:
#!/bin/bash
AGENT='Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1'
page=1
for line in $(cat ...
0
votes
1answer
47 views
Bash script to show range of IP addresses
I want to write a bash script in order to get two IP addresses and shows me whole range between them...
I'm trying but unfortunately no result...
Could you possibly help me?
I found this one but ...
0
votes
1answer
23 views
calling execu in a bash while loop, not working
I have a bash script that has to run the same file (c execut) but with different argument of input and save the output files of the c simulation in different folders. I wrote this but I don't know why ...
0
votes
2answers
40 views
Bash capturing output of find with exclusion into the While loop
I made a script that looks for the content of a folder recursively, excluding some paths, then asks for an action to take on each line of the results.
The find command on its own is working fine and ...
0
votes
1answer
58 views
While true Breaking Bash
I've been writing some bash scripts and for some reason, what used to be working code is no longer working. I had not done any changes, but the while true; do now breaks my bash script.
Here's part ...
-1
votes
1answer
47 views
Bash text database file read in loop
Can anyone see the last syntax error I have made here? The issue is with incrementing the DB"X"FIELDS array. In a way, I'm simulating a mutlidimensional array by storing all records from each database ...
1
vote
3answers
28 views
placements of an error message in while loop with conditional statements
This script checks for the existence of the file every 5 seconds for only 30 seconds.The script waits for the file to appear
If it finds the file it echos “info: done waiting”.
The trouble I am ...
0
votes
2answers
30 views
Check file existance every 30 seconds
why doesn't this work. i need to check the existance of a file every 30 seconds.
STATUS=0
FILENAME="helloworld.file"
while [ $STATUS -eq "0" ] do
if [ -f $FILENAME ];
then STATUS=1;
else
...
0
votes
1answer
44 views
Variable issues in SSH
Hey guys I'm trying to run this code:
#!/bin/bash
sudo /usr/local/bin/sshpass -p pwd ssh -o stricthostkeychecking=no -p 11022 admin@$1.test.com<<EOI
i=1
while read line
do
location="sudo sed ...
0
votes
2answers
56 views
How to add indentation in shell script
I wrote the following script:
while read ligne;
do
echo ${ligne} >> /tmp/test.conf;
other code lines but it's not our probem.
done < <(cat file.conf | sed -ne '/toto/,$p');
...
0
votes
2answers
44 views
How to iterate through string one word at a time in zsh
How do I modify the following code so that when run in zsh it expands $things and iterates through them one at a time?
things="one two"
for one_thing in $things; do
echo $one_thing
done
I want ...
2
votes
1answer
82 views
While read loop only processes the first line;
I have a file with multiple lines and want to do the following with each line..
Set three variables from an awk output.
Do something with the variable data (in my example, echo them).
My script ...
0
votes
2answers
50 views
bash while loop threading
i have a while loop reading lines from a $hosts
while read line
do
ip=$line
check
done < $hosts
my question is can I use some way to speed this up or run the check on 10 hosts at a time ...
0
votes
1answer
61 views
Mistake in while loop? bash script
My Code:
#!/bin/bash
rm screenlog.0
screen -X stuff 'X21'$(printf \\r)
while :
do
grep -i "T" $screenlog.0
if [ $? -eq 0 ];
then
FILE=/etc/passwd
VAR=`head -n 1 $FILE`
echo $VAR
rm screenlog.0
...
0
votes
2answers
68 views
Variable declaration inside bash script while loop
As expected this prints every line of the 'testEmpty' file to the console.
while read i; do
echo $i
done < testEmpty
....but this:
while read i; do
name=$i
echo $name
done < ...
0
votes
1answer
47 views
'calc' in while loop causes undefined variable error in bash script
The following code is a snippet from a larger bash script I'm writing to parse through a sequence of amino acids and carry out calculations based on specific pairs. For simplicity, I have shortened it ...
1
vote
1answer
32 views
Conditional file entry using bash
say i have a bash while loop
while read line
do
#do stuff here
done < $1
I want the entry into the while loop to depend on a comman line argument (e.g. if they type -g it will take their own ...
1
vote
0answers
91 views
Bash Loop on JSON Array
Context:
My goal is to pull the tag from a series of git repos and merge it into an existing JSON (that is the satis.JSON file for a private repo).
Example Data
{
"name": "Example",
...
1
vote
1answer
42 views
While loop not equal command not found
I am trying to perform a simple while loop comparing a variable to a string. It fails to load with the error on this line. Error states [: missing `]' and : command not found. My while loop looks ...
0
votes
1answer
41 views
Deleting files from inside Bash while loop
The code below is failing to delete the files which are listed in
the file called ListOfFilesToDelete.txt and it seems strange.
Is there an obvious (to more experienced programmers) or is it
instead ...
1
vote
1answer
50 views
how do you return error level ($?) after its been piped to while?
in bash i am trying to make a script that goes:
echo hi | while read line; do echo $line; done
&
echo $?
would return 0
lets say the first script messed up somehow:
ech hi | while read ...
0
votes
4answers
66 views
Merging 2 files with the head and tail utilities in bash
My two input files are as follows:
new
111
222
333
old
555
666
I want to merge them to get the following output
111
555
222
666
333
This is what I've tried so far
i=1
while read line
do
...
0
votes
2answers
64 views
no newline in echo/printf in BASH while loop
why on executing following script each printf (tried also with echo) is printed on the same line??
function read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
cat my_xml_file.xml | ...
1
vote
1answer
102 views
Bash script / while loop extremely slow read file
I have a while loop that that reads in a ftp log file and puts it into an array so I'll be able to search through the array and match up/search for a flow. Unfortunately the while loop is taking ...
1
vote
1answer
51 views
Splitting lines in a file using bash and writing back to file does nothing
I'm trying to loop through each line in a file, separate by comma and do something with it. Importantly I want the change to be written to the same file. This code does not give errors but hangs and ...
0
votes
2answers
64 views
bash. while loop with xargs kill -9
I have a list of IP addresses and I have to run a command for every single IP address.
I did it with this code:
array=($(</tmp/ip-addresses.txt))
for i in "${array[@]}"; do
./command start $i ...
0
votes
4answers
55 views
How to loop through file and echo each line with line number
How can I loop through a file, in bash, and echo the line and line number?
I have this, which has everything but the line number:
while read p;
do
echo "$p" "$LINE";
done < file.txt
Thanks for ...
0
votes
2answers
95 views
Return code of the command before the pipe
I'm trying to verify rpms, assign some variables in a while loop and do some more processing inside the loop.
while read fstatus fname rc
do
echo "RC : ${lrc}"
done < <(rpm ...
4
votes
5answers
314 views
How to use `while read -r line` while also checking if another file is not empty in BASH?
I have a while loop, simplified like this:
while read -r line
do
(delete some lines from file2.txt)
done < file.txt
If file2.txt is empty, then this while loop has no need to function any ...
-1
votes
2answers
35 views
Bass: while loop reset a numeric variable
I'm trying to do a simple bash script to do something in one of each file in a set of folders. Also I like to count how many files the script read, but when the script pass of the loop, the numerical ...
0
votes
1answer
70 views
Bash - while loop in a file and stop condition
I want to read a specific value from a /proc file, and currently that's done in a 'while read line' loop, as a scheleton:
while read line
do
if [[ $line = *MATCHES STRING* ]]; then
for (( ...
0
votes
1answer
85 views
Bash loop control while if else with a return
I need to return a true or false if I find a value within a file. I parse the file and if the value is located once which is enough, I want to break and return a true else return false. On top of it I ...
0
votes
2answers
80 views
WHILE loop not looping
I'm fairly new to Linux and shell scripting.
My problem is, that the script should read 2 tokens from a file called "list" - using these tokens, it creates a user and depending on the second token, a ...
0
votes
1answer
197 views
Run script for each line of a file
I'm creating a litle script to run some command on all OpenVZ containers inside a node.
I read all OpenVZ containers ID, and I run some commands on all of them.
Instead in the listvz.txt file I have ...
3
votes
1answer
77 views
simple while loop in bash
I've started learning bash scripting. I wrote simple while loop, but it doesn't work.
it's say that : command not found.does anybody knows why ?
Here is my code:
let x=5; while [$x -lt 10];do echo ...
1
vote
1answer
63 views
HandBrakeCLI command break while loop?
In a bash script, result of find is
/path/to/file1.nrg
/path/to/file2.nrg
/path/to/file3.nrg
i have this while loop:
process preset
processpreset ()
{
x=$1
# Replace , by -o -iname for ...
1
vote
2answers
69 views
bash script, create array of all files in a directory
I have a directory myDir of many .html files. I am trying to create an array of all the files in the directory so I might be able to index the array and be able to refer to particular html files in ...