Programming :: BASH : Using A Loop To Download A Series Of Files?

Feb 2, 2010

Never mind, I figured it out myself. Firstly, the old version of BASH I'm using doesn't support

Code:

for i in {1..27}

So I had to use

Code:

for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Secondly, it was simply

Code:

#!/bin/bash
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
do

[code]....

View 2 Replies


ADVERTISEMENT

Programming :: Bash Programming - Rename Files In A Loop?

Mar 31, 2011

I need to rename the resulted searched files from a loopI have the following code:

find . -name DOC* | while read i
do
find $i -type f -name '*.txt'
done

basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell

View 10 Replies View Related

Programming :: Bash For Loop - All Responses On One Line

Nov 18, 2010

I'm writing a mass snmp toner check which polls any toners available to be snmp polled, however when using a loop statement I get the results on different lines; which sounds good, however the tool I use to check with (nagios) ignores the new lines.

Is there any way I can get the output on one line? Also, I need to raise a fault if any of the toners are below a specific level (with nagios you raise faults with the exit code) - any way I can do this without exiting the loop. Code below with bits and bobs commented out.

Code:
check_ink_levels ()
{
for ID in $INKS
do

[Code].....

View 10 Replies View Related

Programming :: Run SQL Update Statement In A For Loop In Bash?

Jun 7, 2010

The script that Iam trying to write is running a for loop and reading line by line from a text file. inside this for loop i would like to execute update SQL statement .

a pesudo code is
Quote:
`$ISQL -U $username -P $Password -D $Dbname -I $INTERFACE <<QRY
for id in $idlist #idlist iam reading from a file

[code]...

View 8 Replies View Related

Programming :: Sed In A Bash Loop With Ascending Output?

Jan 1, 2011

I have a file like below:

PU12829,24869;PD15733,24869;PD15733,19785;PD12829,19785;PD12829,24869;
PU4599,20915;PD9924,20915;PD9924,18898;PD4599,18898;PD4599,20915;
PU12829,24869;PD15733,24869;PD15733,19785;PD12829,19785;PD12829,24869;
PU4599,20915;PD9924,20915;PD9924,18898;PD4599,18898;PD4599,20915;
PU1723,3423; #this line is ignored to short

[Code]...

What I'm trying to do is while true, cut each line from file that begins with PU and thats longer than 12 characters and write to a increasing numbered file for each line. Stating with object1 etc.

View 14 Replies View Related

Programming :: Using A Variable To Control A BASH For Loop

Jul 3, 2009

I know of 4 different ways to use a for loop:

1. for I in {1..10}; do echo $I; done|

2. for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done|

3. for I in $(seq 1 10); do echo $I; done|

4. for ((I=1; I <= 10 ; I++)); do echo $I; done

I have a script which uses the 1st form of for loop. I'm trying to modify it to use a variable instead of a static hard-coded value in the section that controls the looping.of the for loop.

I've tried all different ways of quoting and escaping the variable, and the problem is that the quoting chars and escape char are being translated and passed into the loop along with the value stored in the variable.

For example, to change the start value of 1 to whatever value I want passed in through a variable:

Change:

I have tried: {{$a}..10} and {`$a`..10}, to have the variable evaluated first.

I have tried using the eval() function.

I have tried single and double quotes and the backslash escape character.

Nothing I've tried works. It's probably a syntax error.

View 14 Replies View Related

Programming :: Bash Script That Reads Lines In While Loop

May 26, 2011

So I need to write a bash script that can read lines and column 3 from a file. It needs to start on line 16 and read every 20th line starting from there. But the value that it reads needs to be checked, should it be too great I need it to shut the program down.I'm pretty new to bash, but my ultimate goal is being able to safely run a program on a GPU for an extended period of time with out worrying about it overheating. I have a command that outputs information from the GPU every second, and I can save this to a file. So all I really need is something to read and check that file, I played around a bit with the awk command and can't get it to work within my for loop with dynamic variable.

View 7 Replies View Related

Programming :: Bash To Loop Through Mysql Select Array?

May 26, 2011

I need to know how to assign a result from a select. I am clueless on the sytax. I am trying this in bash. Maybe I am not assigning the array right. It gives me the whole row in the echo instead of just field a. How do I get fieldA = a in the select. Note script was stripped for security on database info but the syntax is same.

Code:

#!/bin/sh
results="$(mysql --user ${DB_USER} -p${DB_PWD} ${DB_NAME} -Bse 'select a,b,c,d from tblMytable')"
for rows in "${results[@]}"
do
fieldA=${rows[0]};
echo ${fieldA};
done

View 2 Replies View Related

Programming :: Bash Step Incremental Loop To Stop On Each Increment?

Jul 17, 2011

How do I get this loop to stop on each increment? This script does work but I would like it to stop at each increment, remember what the value of $n is, then continue until it gets to 7. I have worked so hard on this. My brain is hurting now.

[Code]...

View 2 Replies View Related

Ubuntu :: Accessing And Creating Files Names With Nested Loop In Bash?

Aug 12, 2011

nested loop in ''Bash-Scripting in Linux'' ?What's wrong with my code:

for x in `seq 0.75 0.01 0.95`
do
for y in `seq 0.20 0.01 0.40`

[code]....

View 1 Replies View Related

Programming :: Sed - Series Of Files In The Format

Sep 21, 2009

I have a series of files in the format:


Which I'm trying to split using sed to have each field/value pair on on line:

So far so simple, but some of the values might have commas in them, which means they'll be split up. Is there a way to change this so that only commas not within quotes will be replaced with ? (e.g. make sed count number of " and if it finds a , after counting an odd number of " then ignore it?)

View 2 Replies View Related

Programming :: Bash Variable Parsing / Extract And Put Into Variables Each Combination Of F1 And F2 In A Loop?

Oct 14, 2010

I have a bash variable where the content looks like this where ;f1; and ;f2; are delimiters:
;f1;field1value1;f2;field2 value1 ;f1;field1value2;f2;field2 value2 ;f1;field1value3;f2;field2 value3

So what I need is to extract and put into variables each combination of f1 and f2 in a loop to something like that:

#first pass of the loop I need:
f1=field1value1
f2=field2 value1

#second pass of the loop I need:
f1=field1value2
f2=field2 value2

# third pass of the loop I need:
f1=field1value3
f2=field2 value3

View 15 Replies View Related

Programming :: Generating Files With Different Names At Each Loop In Fortran?

Nov 7, 2010

I am trying to write a loop to open four main-data-files. At each open of the main-data-file, I want the loop to open another four sub-files and split the data from the mail-data-file according to the creteria and dump into the four files. When the loop goes to the second main-data-file, it shall generate another 4 sub-files with different file name. And the process goes on. That means I will have total of 16 sub files for the four main-data-files. Each four files from the 16 files shall have specific name on it. Based on the code which I given below, I would say when the file at UNIT=100 is opened, 4 new files needed to be opened as well. They are:

maximum_dist_001_064.dat
maximum_dist_065_128.dat
maximum_dist_129_192.dat
maximum_dist_193_256.dat

View 1 Replies View Related

Programming :: What Are The Series Of Files That Are Called When A User Make Copy Operation From Usb Mass Storage To Hard Disk

Mar 20, 2010

what are the series of files that are called when a user make copy operation from usb mass storage to hard disk?i have reached the code of the usb mass storage in linux kernel 2.6.33 and i want the exact code the make the copy how can i do that?

View 2 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:

Code:

Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 Replies View Related

Programming :: Bash Script To Download A Directory Structure And A File?

Mar 20, 2009

I want to read an ftp site [URL]...and download the sub-directory structure and ONLY the tagfiles to the local directory.

FROM THIS:

Code:

slackware
+--a
| |aaa_base-12.2.0-noarch-1.tgz
| |aaa_base-12.2.0-noarch-1.tgz.asc

[code]....

I tried wget + grep but that didn't work too well.

View 2 Replies View Related

Programming :: Read Two Files Word By Word At A Time Using Any Loop By Shell Script?

Mar 4, 2010

Well, I am facing one issue:How can i read two files word by word at a time using any loop as i need word by word comparision in shell script?Please let me know pseudo code.

View 14 Replies View Related

Programming :: Download Files Using Perl?

Jul 24, 2010

How do I download a file to a specified location on disk in Perl?I tried doing a few web searches but suprisingly couldn't find anything.

View 4 Replies View Related

Programming :: PHP - Upload And Download Files

Jun 1, 2011

I want to know what is the best way/practice to let users upload and download files? I want to be able to let the user upload a file, list all the files uploaded, and allow him to download any file from that list, also delete a file. To my understanding I can make a php script to let them do this and the uploaded files are in a specific folder in the server or I can insert the files into a SQL table. Which direction should I go, let them directly upload the files to a specific folder (no SQL involve), or upload the files into a SQL table?

View 1 Replies View Related

Fedora :: Bash: While Loop Will Not End

Jan 9, 2010

This gives a selection menu where you choose an option, and it should continue. I have several of these as part of a much larger script, but something is wrong with this while loop.

Code:
VARIABLEINPUT="1"
if [ $VARIABLEINPUT == "1" ] ; then
echo -e "${YELLOW}How often would you like the automatic update and maintenance to occur after the installation?:
${RED}1)${WHITE} Hourly
${RED}2)${WHITE} Daily
${RED}3)${WHITE} Weekly
${RED}4)${WHITE} Monthly
"
[Code].....

A very simple loop that uses a variable from earlier in the script to adjust variables for later in the script. For some reason, this while loop will not end - I've noted where with echos.

View 4 Replies View Related

Security :: Bash: Can't Su Within While Loop

Jul 18, 2010

I have a while loop in a file that looks like:

Code:

while IFS=":" read name script
do
su
exit

[code]....

Where I redirect the file into the loop, for some reason, I can't do an su when I redirect a file like that. I get the error, "su: must be run from a terminal." Why is this? How can I fix it?

View 7 Replies View Related

Programming :: List Files In Bash + Add Url Before Them?

Dec 8, 2010

I am an uploader to a various hosts, so this tiny script me a lot. I make a rar archive and split files with 100mb. I could get 3-4 or even 76 parts of rar files and it would take me some time to paste all these urls to remote upload function of filehosting sites. For example:

Code:

server:/home/cober/downloads/teevee# ls -al
total 358784
drwxrwxrwx 2 root root 4096 Dec 8 19:38 .

[code]....

View 1 Replies View Related

General :: Bash For Loop Not Working?

Apr 21, 2010

I have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?

Code:
for a in {1..10}
do
echo -n "$a "
done

View 5 Replies View Related

Programming :: Bash Script To Copy Files?

Jul 13, 2011

I have a lot of filenames (strings) following the same convention

m02_+1+7_London_0000$01.cfg
m02_+1+8_London_0000$01.cfg
m02_+1+8_London_0000$01.cfg

[code].....

What I want to do is to create a script that will interpret the following string and save into variables part of its name

m02_+1+7_London_0000$01.cfg as
------X-Y--City---------
X=1
Y=7
City=London

[code]....

then I want to copy the files that go all the files with the same City and X and Y to the same subfolder City/MX.Y I will need some help start doing that. And I think the first would be to get part of the filenames strings into variables.

View 3 Replies View Related

Programming :: Bash Find Files On Time Help?

Mar 11, 2011

I am trying to find a nightly backup if it was successfully copied over, rename it and curl, but it's always passing the check even if the file is older than specified. From the command line it does as it should. Example is here;

Code:
find /backup -type f -mmin +4440 -exec echo "found" {} ;
- nothing returned (good). Then I change the time

[code].....

View 4 Replies View Related

Programming :: Bash Function For Searching Files ?

Jun 15, 2011

I'm making a small script for searching and doing some operations with photos, but I'm kinda stuck on this little function:

Code:

function findallformat {
prefix=""
if [ $1 = -pre ] then

[code]....

That function should find for every file with a certain type; and you can specify a prefix using a "-pre" followed by the prefix that you want to search. The format should be "stackable", so you can use as many types that you want, without repeating the same function on the code.

Example: findallformat -pre IMG_ .JPG .CR2 #That should search files that start with "IMG_" and finishes with .JPG and .CR2. My problem it's that, when I try to use it on the script, it says "bash: syntax error near `token' unexpected `}'"

View 4 Replies View Related

Programming :: Catch Some Outputs In Two Different Log Files In Bash?

Jan 26, 2009

I want to catch some outputs in two different log files in bash, file simple.log and all.log So far, the script is started like this:

Code:

xterm -e "(./myscript.sh | tee -a simple.log) >& all.log"

What I want is:

- In simple.log, I want all the stdout but WITHOUT errors.

- In all.log I want BOTH stdout and stderr.

So all is ok, and the output becomes:

all.log

Code:

starting copying files
mv: cannot move ... : permission denied
copying completed
simple log

Code:

starting copying files
copying completed

But, in the new xterm, I'm loosing stdout. There is no output.How can I have the files logged as they are but also have the stdout in the xterm.

View 6 Replies View Related

Programming :: Bash - Renaming Files Won't Work

Apr 1, 2010

I'm trying to rename a lot of files getting rid of the space on the names. For that purpose I wrote this very simple bash script, but for some reason is not working.

Code:
for i in "$(ls)"
do
j=$(echo "$i" | sed 's/ /_/g')
mv "$i" "$j"

done But what I get in return for each line is just one long file name with all the file names concatenated. I've tried with echo -e "$i" as well with no results. This has to be something really simple that I'm missing but I just can't see it.

View 11 Replies View Related

Programming :: Reading Files In A Directory Using Bash?

Nov 6, 2010

I am trying to write a simple script to list all the files in a directory. The script I wrote was as below where the pdb_files is a directory and all the files which I want to list are in that folder.

Code:
files=`ls -F pdb_files/*THERMO*`
for inFiles in $files
do
echo $inFiles

[Code]....

View 5 Replies View Related

Ubuntu :: Bash Menu Option Loop

Mar 19, 2010

I am trying to make a bash menu that loops with options but it does not work as I want:

Code:

I want to make it read an option and do the action then return to menu.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved