0
votes
1answer
32 views

While read from line in shell script sh linux

I am reading from a file in sh shell script and I want to remove one line from the file if the condition succeeds. if [ -f "file.txt" ]; then while read line do if ...
1
vote
1answer
39 views

Run a command until return code greater than x

In a bash script I need to run a command until the return is bigger than 127. For now, i'm running the command in an subshell, with the outputs to /dev/null and printing the return code to be able ...
1
vote
1answer
26 views

Mutiple conditions in OS X bash script WHILE loop

Basically what i want to do is read in a variable from std input and check if the variable is 1 or 2. if it is not i want to inform the user and ask again, i thought a while loop was made sense (i am ...
1
vote
3answers
60 views

Difference between `exec n<&0 < file` and `exec n<file` commands and some general questions regarding exec command

As I am a newbie in shell scripting, exec command always confuses me and while exploring this topic with while loop had triggered following 4 questions: What is the difference between the below ...
2
votes
3answers
82 views

How to show the values in the LOOP for every 10 second in java

I have a while loop where in it constructs a JAVA String by appending the output from a shell script. System.out.println("Here is the standard output of the command:\n"); while ((s = ...
0
votes
1answer
51 views

while loop is not working in shell script

Wednesday, May 21, 2014 10:09 AM I am running below two programs first program: while read line do if (cat /etc/passwd | grep -w ^"userid") then echo $line fi done < serverlist output: ...
0
votes
2answers
268 views

Run a shell script with While condition in an infinite loop based on conditions

I need to create a shell script to place some indicator/flag files in a directory say /dir1/dir2/flag_file_directory based on the request flags received from a shell script in a directory ...
0
votes
2answers
63 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
65 views

To redirect output to screen instead of csv file

There is a shell script I am running which reads some columns fron the file and write it to the csv file. Like the compilation of the records from the two files. #!/bin/ksh while read -r a1 a2 a3 ...
0
votes
1answer
74 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 ...
1
vote
1answer
36 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 ...
0
votes
2answers
292 views

Adding Number increments to Variables

I have a file which has N number of lines. I need to read each line and store it in a variable. For example, Firstline in var1, Secondline in var2, etc. I tried the below while loop, count=1; while ...
0
votes
1answer
46 views

overwrite a file only after the while loop finishes in shell script

In my shell script I am writing the results of a while loop in an output file, so the output file looks like this: 23 34 45 35 But when I use > instead of >> I only get the last ...
0
votes
1answer
990 views

increment a variable value inside a while loop in a shell script

I'm trying to increment a variable value in a while loop, but I want to increment it twice. By "twice" I mean increment variable value first time, then do some operation and then increment already ...
2
votes
1answer
61 views

For Loop : how to limit the activity for just 1st occurance where there are multiple matches in the loop

I am trying to execute a command that needs to run just ONCE for each distinct match of a SID in a file and there are many files out there in a the directory that share a SID.That is SID to (# files ...
0
votes
2answers
85 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
335 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 ...
0
votes
3answers
68 views

Do while loop . Make exception for the 1st record and continue on the loop as usual

I have do while loop that'll get filenames and run commands. Pretty standard stuff . What I want to do is sort the files that I feed to the Do While loop and then for the 1st file I want to run a ...
1
vote
2answers
226 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 ...
0
votes
1answer
98 views

Shell Script and user input

I'm writing a script, and plan on it being interactive. It's kind of like a scavenger hunt. The script basically greets the user and gives the user instructions on how to proceed. The instructions ...
0
votes
3answers
123 views

How can I increment a number in a while-loop while preserving leading zeroes (BASH < V4)

I am trying to write a BASH script that downloads some transcripts of a podcast with cURL. All transcript files have a name that only differs by three digits: filename[three-digits].txt from ...
1
vote
2answers
403 views

The variable inside while loop is not remembered. Mysql bash script auto_increment

I've working on this script for quite some time. But I started to see some errors when I tried to add a variable ($EMAIL_MSG) to store some strings of text to later be emailed. It seems that the ...
-1
votes
3answers
53 views

while loops offset in shell script

I/P file has data as follows: Y REQUIRES Z A REQUIRES B C REQUIRES D REQUIRES E REQUIRES F G REQUIRES H I REQUIRES J EXACT OUTPUT FILE REQUIRED: Y REQUIRES Z A REQUIRES B C REQUIRES D C REQUIRES E ...
0
votes
2answers
1k views

to delete files older than 7 days using Unix

Requirement: i am having the path where the files will be present . i need to get the path from it and delete the files older than 7 days with name as .logo or ,out0 .. ISSUE:tried the below but ...
2
votes
5answers
65 views

Separating and counting number of elements in a list with conditions

I would like to separate and count the number of elements within my input list. The input.txt contains 2 columns, $1 is the element ID and $2 is it's ratio (number). ENSG001 12.3107448237 ENSG007 ...
0
votes
3answers
441 views

Shell script: use while loop to check string contents using [ ]

I am trying to check a string that is output from a program, if the string matches a certain content, the while-loop will stop the program. At the same time, I need to count how many times the program ...
0
votes
1answer
142 views

Linux shell scripting error with while loop syntax

#!/bin/bash initial="/" usrname=`cut -d ":" -f1 users.txt` password=`cut -d '"' -f3 users.txt|cut -d ":" -f2` comment=`cut -d '"' -f2,3 users.txt|cut -d ":" -f1` path=`cut -d "/" -f2,3 users.txt` ...
1
vote
2answers
86 views

Combine text from two files, output to another

i'm having a bit of a problem and i've been searching allll day. this is my first Unix class don't be to harsh. so this may sound fairly simple, but i can't get it I have two text files file1 ...
0
votes
3answers
70 views

while loop on list with spaces

I'm trying to run a for loop which will replace strings within files passed as a list. Example: Filename1 Filename2 File name3 File name4 My current code is: for i in `grep -Rl 'OLD' *`; do ...
2
votes
3answers
118 views

Check regexp condition inside while loop (shell)

I have problem with running my simple shell script, where I am using while loop to read text file and trying to check condition with matching regexp: #!/bin/sh regex="^sometext" cat input.txt | { ...
1
vote
2answers
85 views

Here Strings: What is going on here?

I'm relatively new to shell scripting, but not to programming, though I'll admit to being out of the game for a while. In trying to get the bottom of a bug in a Bash script, I've come up with three ...
1
vote
1answer
45 views

Shellscript Ubuntu Find out if a user entered a specific character

I want to do a while loop until the user enters ab "@", this is my code but its not working: echo -n "username(email): " read username checkEmail $username checkEmail () { username=$1 echo ...
1
vote
2answers
794 views

file system creation script on AIX using while loop

#!/bin/sh echo "VG: " read VG echo "LP: " read LP echo "SAP: " read SAP echo "NUM: " read NUM echo "SID: " read SID while [[ $NUM -lt 2 ]]; read VG LP SAP NUM SID ; do mklv -y $SAP$NUM -t ...
2
votes
1answer
752 views

Why is a for loop faster than a while loop in the shell?

Preface: I've always been taught that when working in the shell, it is preferable to do while loops over for loops, and that you should not use for loops with command substitution cat'ing a file. My ...
0
votes
2answers
7k views

bash shell while loop how to break out

I want to write a bash shell script to process text, which might require while loop. For example, a while loop in c: int done = 0; while(1) { ... if(done) break; } I want to write a bash shell ...
1
vote
1answer
1k views

bash while loop not exiting and not echoing

So I have this bash script function exec_do(){ while [[ 1 ]]; do read _INPUT if [$_INPUT -eq "exit"] then break else echo $_INPUT fi done } The intention is so that if I type in ...
0
votes
2answers
121 views

How to periodically check if any file changed and then build

I would like to monitor directory for change and if any file in that directory changes then I would like to build software. How can I do it with a shell "oneliner" ? I was trying some variations of ...
1
vote
4answers
168 views

Joining and comparing a large number of input files from bash

I want to read lines from 29 files and processing these lines and putting them in if statement. In this example i created 3 sample files and one shell script file which basically reading files using ...
0
votes
2answers
304 views

Unix shell script for increment the extension

I have file getting generated (testfile) eachtime a script is run in working directory. I have to copy that generated file to a directory (testfolder) and have it incremented by a .ext If the script ...
0
votes
3answers
2k views

exit statement will not break while loop in unix shell

The exit statements in each status check if statement do not break the while loop and truly exit the script. Is there something I can do to break the loop and exit with that $STATUS code? EDIT: I've ...
0
votes
2answers
403 views

Shell script to poll a directory and stop upon an event

Need shell script to: 1/keep polling a directory "receive_dir" irrespective of having files or no files in it. 2/move the files over to another directory "send_dir". 3/the script should only stop ...
0
votes
4answers
4k views

“unary operator expected” in shell script

I need a script to keep polling "receive_dir" directory till "stopfile" get written in the directory. This has to run despite empty directory. So far i have this but fails if receive_dir is empty ...
1
vote
2answers
4k views

Bash while loop with two string conditions

I have run into a bit of a problem with my bash script. My script among other things is starting a server that takes some time to get going. In order to combat the long startup, I have put in a while ...
0
votes
1answer
131 views

Shell: Run PHP script and wait for it to finish

I need to write shell script, which will run PHP script every x seconds. And I need to be sure, that previous execution has finished. Is it possible to run PHP script from shell and (for example) ...
0
votes
2answers
1k views

Shell script while loop not exiting

I have a shell script with a while loop which is not exiting out.The wget statement will return me true or false. I need to execute the commends till the value is true #!/bin/bash status="false"; ...
0
votes
2answers
196 views

While loop is not reading a '\' from a file in shell script

I am trying to read a line in a file which has '\' in it. But it is not showing in output, please help me what is the reason behind and how to read it. Ex: File has this data: abc abc\def but ...
2
votes
2answers
241 views

Bash: Odd behavior reading from STDIN in a loop

I observe a behavior that I don't undrestand and would like someone to shed some light on it. I have two scripts, both read from STDIN. Reading a sequence of numbers from keyboard ( 1 enter 2 enter ...
0
votes
1answer
4k views

WHILE loop - read line of a file one by one — Not working the No. of times the file has lines in it

I'm using a "while" loop within a shell script (BASH) to read line of a file (one by one) -- "Fortunately", its not working the No. of times the file has lines in it. Here's the summary: $ cat ...
0
votes
1answer
1k views

unix Syntax error near unexpected token 'done'

This script #!/bin/sh once=true while $once do stop & PID=$! sleep 10M if [$!=0]; then start break else kill $PID fi done Gives ./restart.sh: line 18: syntax error near unexpected token ...
0
votes
2answers
160 views

Bash while statement - infinite loop

#!/bin/bash CHECKUSER=$(grep "$USER" /var/log/string.log) if [[ $CHECKUSER == "" ]]; then echo "Please enter y or n? (y/n)?" read string if [ "$string" = "y" -o "$string" = ...