The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
1answer
46 views

Func name as variable in loop

Overview: I save my variable in a config file and call them later. Each entry with the name FailOverVM has a number beside it like FailOverVM1 and I want to check to see if it has data and generate a ...
1
vote
1answer
43 views

bash for loop variable not changing

I am iterating over indexes which are used to create data file id's. When I create the file name (data_file) and echo it, it prints properly, but when I try to sed that variable into the desired files ...
-2
votes
1answer
45 views

Write shell script for logging in servers and run command after logging in

I have wrote a shell script for logging into servers and run few commands to start and stop processes running on it, So I tried below code, but it is showing error, please help me with the script. ...
0
votes
1answer
32 views

How to use 7z and “for file” with multiple file inputs?

I have multiple files in a folder like: 1.txt 2.txt 3.txt ... 100.txt And I want to use 7z to compress single files, generating 1.7z, 2.7z 3.7z... I'm trying to use for file in {1..100} ./{1..100}....
1
vote
1answer
24 views

Question about if structure and loops

I am new in programing with bash script. Here is my problem: I am going to open a sort of data whose file name includes the date (format: file_yyyymmddhh.nc). There are some requirements: mm is ...
0
votes
2answers
79 views

For loop runs twice,

So I am fairly new to bash scripting, but I want a bash job that will: Create a post-dated timestamp. (either as a var, or to a file) Read lines from a file named feeds.txt. Separate the number ...
1
vote
3answers
111 views

how can we use multiple variables in single for loop in shell script?

I am implementing as below code using for loop but wrong output coming after running the script. for i in `awk -F"|" '{print $1}' $INPUTFILE`, j in `awk -F"|" '{print $2}' $INPUTFILE` do echo $i:$j ...
-1
votes
1answer
41 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 /...
0
votes
1answer
48 views

Loops: for vs while… beyond the basics. Subtle differences/pros/cons for my code? [closed]

I have been writing/refining a relatively complex code for the past year, and learning bash along the way. My code is filled with functions that have complex multi-level while loops. I've recently ...
1
vote
1answer
77 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ....
3
votes
2answers
50 views

Iterating over glob patterns, not the files in them

I would like to perform the same aggregation operations on each of several bunches of files where each bunch is matched by one glob pattern. What I would not like to do is pipe each file name into the ...
1
vote
0answers
45 views

Assigning floating point value to array in Unix shell script loop [closed]

I am using ksh scripting on Ubuntu 14.04 and am trying to write a script to add floating point numbers to an array. My code is as follows numLoops=6 numerator=14996288 denominator=1000000000 for i ...
1
vote
2answers
137 views

How do I use a temporary environment variable in a bash for loop?

I want to run YII_ENV=prod yii kw/test ten times. I tried $ YII_ENV=prod for x in 1..10 do; yii kw/test done; -bash: for: command not found 1304682651 (Seemed to run once.) I also tried $ for x in ...
1
vote
1answer
18 views

Create subdirectories under a parent but prompt for the name of the parent

I use SCP a lot to transfer log files from servers to a jumpbox where I can analyse and troubleshoot etc. If I have a cluster of servers and I want to create a set of subdirectories I do it like this: ...
6
votes
2answers
178 views

for loop over input lines

I have a file with a lot of lines like this /item/pubDate=Sun, 23 Feb 2014 00:55:04 +010 If I execute this echo "/item/pubDate=Sun, 23 Feb 2014 00:55:04 +010" | grep -Po "(?<=\=).*" Sun, 23 ...
0
votes
0answers
18 views

Loop through directory and sum value next to specific pattern producing an average

I want to loop through all the files in the directory. the files are set out like this: <Overall>4 other data <Overall>2 other data ...... I have the code: for file in .dat; do awk '...
0
votes
1answer
33 views

regex to remove last four characters

Is there a way I could eliminate the last four characters with regex in the below one line script as I convert .wav files into .mp3 files. As of right now my single line script produces files ending ...
3
votes
4answers
370 views

How do you create a for loop with a changeable number of iterations?

How do you iterate through a loop n amount of times when n is specified by the user at the beginning? I have written a shell script and need to repeat a certain part of it n numbers of times (...
0
votes
1answer
34 views

Skip for loop iteration depending on response to inner select

I have the following bash script, which iterates through all the images in a directory and attempts to determine the date and time it was created using exif. If the exif information is not available, ...
-1
votes
2answers
67 views

bash shell script two variables in for loop

for SLAVE_CLUSTER,MASTER_CLUSTER in $MASTER_CLUSTERS $SLAVE_CLUSTERS do echo "Master cluster boxes are ${!MASTER_CLUSTER}" echo "Slave cluster boxes are ${!SLAVE_CLUSTER}" done I am ...
-1
votes
2answers
51 views

Script with nested for loops [closed]

This is the code and I need to display in the terminal like this way: (1,1) (1,2) (1,3) (1,4) (1,5) (2,1) (2,2) (2,3) (2,4) (2,5) (3,1) (3,2) (3,3) (3,4) (3,5) (4,1) (4,2) (4,3) (4,4) (4,5) but ...
0
votes
2answers
112 views

for loop in bash

I want to create a for loop that runs from 1 to a number stored in a variable. But it produces this error: Syntax error: Bad for loop variable This is my script: #!/bin/bash count_lines () { ...
0
votes
0answers
105 views

Make whiptail work in a for loop

This is my first question ever here... So please be gentle :) I have a bash script that checks ping for 163 sites(stores around the country), which is this: #!/bin/bash #storestest.sh #version 0.9.2 ...
0
votes
1answer
146 views

Bash For Loop - prompt for IP range and password

I have a simple for loop one liner I use to check for things across a number of servers that have the same password set. I want to develop this one liner into a script that logs into a cluster of ...
1
vote
1answer
20 views

How do I write a script to automatically compile and install all Moksha modules?

I have this repository cloned on my Sabayon machine, what I would like to do is write a script that will change into each directory of this repo (just the top-level directories, not directories inside ...
2
votes
2answers
597 views

How do I get ~/.bashrc to execute all scripts in my ~/Shell directory using a loop?

I have shell scripts in my ~/Shell directory that I want to be run whenever Bash is started up as my usual user account. So what I have done is added the following to ~/.bashrc: for i in `find ~/...
3
votes
1answer
61 views

Shell script - Couldn't find 'fi' for this 'if'

I have found this error alongside couple more. I believe that the nesting is not quite all right or the for is not correctly indented or without some semicolon. Either way I have tried for quite some ...
1
vote
2answers
120 views

Efficient way to search array in text file by AWK

I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will ...
-2
votes
1answer
30 views

help me with create shell script with bash scripting [closed]

I want to make the script to extract the users of linux server and check if "/home/$user/public_html/vb/includes/config.php" is exist , i want the script to check all the users in the server and ...
0
votes
0answers
14 views

How to copy files which includes spaces [duplicate]

I have the code below: for i in *.pdf; do mv $i books/; done This line of code selects file by words not the whole file name, so when it tries to move "The code of valamor.pdf" it gives the output ...
1
vote
0answers
38 views

Cannot terminate for loop in terminal

I was running a for loop in terminal which has a sox command in it. For some reason the sox command failed and now I cannot terminate the for loop. I tried pressing Ctrl+c many times, Ctrl+z many ...
1
vote
0answers
173 views

csh: redirecting output from foreach

In csh: How do I redirect the output from a foreach-loop to a pipe? This works but uses a temp file: set tmpfile=/tmp/file ...
1
vote
2answers
40 views

extract part of the text from all matching lines

I am running a for loop against set of servers to find the cert expiry. Output of the cert command will be below for each server: line 1 line 2 line 3 Valid From: Tuesday, 29 September 2015 10:40:13 ...
1
vote
2answers
158 views

SSH to servers with sudo access - script throws unexpected end of file error

I've to run a command iptables --flush in 100+ servers. I don't have root credentials, but have sudo access for my account. So I come up with a below script to run the command in all servers. I added ...
-2
votes
1answer
67 views

Find part of filename

Please help with my task: I have a folder with three sub-folders containing six files each. There are two files in each sub-folder with :nopm in their file names. I need to create a shell script ...
0
votes
0answers
85 views

Directory research example

I have a folder with three sub-folders containing six files each. There are two files in each sub-folder with :nopm in their file names. I need to create a shell script that checks all the folders ...
2
votes
1answer
30 views

Copying directories unrelated file names

Apologies for the dumb question. I'm trying to copy directories of data sets that pertain to the a certain case but the data sets are currently stored in different directories and with different (non ...
1
vote
2answers
70 views

Help understanding bash script

I'm a bit stuck trying to understand the following script from a book: values=(39 5 36 12 9 3 2 30 4 18 22 1 28 25) numvalues=${#values[@]} for (( i=0; i < numvalues; i++ )); do lowest=$i ...
3
votes
4answers
242 views

Help with bash script

I am teaching myself bash scripting with the book 'Learning the Bash Shell' by Newbam. I'm getting on OK with the book, but am a bit confused by the following script. It is a script which uses a for ...
8
votes
4answers
1k views

bash loop with 0.02 increment

I want to make a for loop in bash with 0.02 as increments I tried for ((i=4.00;i<5.42;i+=0.02)) do commands done but it didn't work. I appreciate if you help me out.
0
votes
1answer
259 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command sets from a file and then execute each over a set of files. The prepared file should serve as a template for execution in manual ...
6
votes
2answers
13k views

In a loop over an array, add an element to the array

I have a problem with for loop in bash. For example: I have an array ("etc" "bin" "var"). And I iterate on this array. But in the loop I would like append some value to the array. E.g. array=("etc" "...
0
votes
2answers
40 views

Script to find logs in directory

I have my loop for: for i in 1.34* do if [ -f $i/rela/*log ] ; then echo $i >> /tmp/allog else echo $i >> /tmp/alnolog fi done Is working well. We have different version of releases ...
2
votes
1answer
904 views

For Loop for Google Image Downloading Bash Script

I have a bash script which downloads images from Google Images. This is the command I use: bash getimages.sh 3 rocky%20mountains That command will download the 3rd picture in Google Images. To ...
0
votes
1answer
45 views

How to grouped the following variable and command and read 1 by 1

I've following array and variable : httpurl="http://www.nnin.com" firstquery=$(curl -s -X POST -d "UID=user1&PWD=1111" $httpurl) name="firstcust" ip="105.105.0.1" httpurl="http://www.mmim.com" ...
0
votes
2answers
100 views

Variable in for loop to be used as an array for a csv output

I've been struggling to come up with a solution for this, the goal is to organize the results into comma separated columns as we have to recable our entire datacenter from cat6 to cat6a. $DBFILE ...
2
votes
3answers
69 views

Bash | port killing loop fails

I am trying to create a bash function which should kill all processes using some ports specified in port_array. The kill-port function works if I call it myself with a port e.g. with kill-port "80";. ...
0
votes
2answers
97 views

How to use 3rd variable in BASH for loop?

Good day. I want to parse data of particular columns from several files(aprilPlate.txt, mayPlate.txt, junePlate.txt, julyPlate.txt, augustPlate.txt) using For loop. The data of input files (...
0
votes
4answers
2k views

Foreach loop for ls output

I am trying to process some files in directory using foreach loop for ls output: IFS=$'\n' for i in $(ls -1Atu); do echo "$i" done At first time i thought it works, but when i created file ...
6
votes
4answers
593 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...