06-11-2009
File Names in a Variable in a loop
Hi All ,
I am having confusion in a shell script. Please guide me.
I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server.
Actually, i call the FTP function in a loop. At the last step, i need to move all the get files to the target directory.
<Sample Code>
FILE_COUNT=`echo "${SOURCE_FILE}" | tr '|' '\n' | wc -l
COUNTER=1
while [ ${COUNTER} -le ${FILE_COUNT} ]
do
FILE=`echo ${SOURCE_FILE} | cut -d '|' -f${COUNTER}`
<FTP Function>
if [[ ${COUNTER} = ${FILE_COUNT} ]]
then
mv <All the Source File Names> <Target Directory>
fi
done
<Problem>
How can I hold all the file names in a variable like below in the loop.
FileNames=FileName1 FileName2 FileName3 ... FileNameN
mv $FileNames $TargetDirectory
Please help me how can i achieve.
Thanks,
Kanda.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I am trying to process error files in selected directories. I can count the files that are there and export the contents to a file for either emailing or printing. The next step is to move the files to a processed directory with the name changed to .fixed as the last extension.
for file in... (2 Replies)
Discussion started by: jagannatha
2 Replies
2. Shell Programming and Scripting
Hello,
I have a question regarding file naming under a loop in tcsh. I have the following code:
#!/bin/tcsh
foreach file (test/ProteinDirectory/*) # The * is a bunch of ProteinFile1, ProteinFile2, ProteinFile3, etc.
sh /bioinfo/home/dgendoo/THREADER/pGenThreader.sh $file $file
... (4 Replies)
Discussion started by: InfoSeeker
4 Replies
3. Shell Programming and Scripting
Simple enough problem I think, I just can't seem to get it right.
The below doesn't work as intended, it's just a function defined in a much larger script:
CheckValues() {
for field in \
Group_ID \
Group_Title \
Rule_ID \
Rule_Severity \
... (2 Replies)
Discussion started by: Vryali
2 Replies
4. Shell Programming and Scripting
i=0
while
do
sizesfor0=`cat 16 | grep 'pickSize' -A 1 | grep '_sz' | cut -d'_' -f1`
sizesfor0=${sizesfor0//id=\"lll/:}
IFS=: array0=( $sizesfor0 )
echo ${array0}
i=$(( $i + 1 ))
done
So, right now I have two variables in the while statement above
sizesfor0 and array0
The... (1 Reply)
Discussion started by: phpchick
1 Replies
5. Shell Programming and Scripting
OS : RHEL 6.1
Shell : Bash
I have lots of files in /tmp/stage directory as show below.
Using a loop, I need to print all the filenames in this directory except those ending with a number. How can I do this ?
# pwd
/tmp/stage
#
#
# ls -l *
-rw-r--r--. 1 root root 0 Oct 7 18:38 stmt1... (2 Replies)
Discussion started by: kraljic
2 Replies
6. UNIX for Dummies Questions & Answers
Hi Fellows,
I was wondering how I can remove first few characters from multiple file names without do loop in unix?
e.g.
water123.xyz
water456.xyz
to
123.xyz
456.xyz
Thanks
Paul
Thanks. (3 Replies)
Discussion started by: Paul Moghadam
3 Replies
7. Shell Programming and Scripting
I'm trying to grab a list of file names from a directory, then process those files 5 at a time. In the link below. Instead of using files I'm using the files array which contains 15 strings starting with AAA.
So I'm trying to assign $fileset 5 of the strings at a time to pass to a command. So... (4 Replies)
Discussion started by: zBernie
4 Replies
8. Shell Programming and Scripting
Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies
9. Programming
Hi guys
I'm a beginner in fortran. So excuse me for my naivety, let me briefly describe what I was trying to do. I have let's say 2 files named reac-1 and reac-2. After opening these files I've to do some calculations, close these files and open the same files again in a loop. So my faulty code... (6 Replies)
Discussion started by: saleheen
6 Replies
10. Shell Programming and Scripting
As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2.
for file in /home/cmccabe/Desktop/comparison/missing/*.txt
do
file1=${file##*/} # Strip off directory
getprefix=${file1%%_*.txt}
... (5 Replies)
Discussion started by: cmccabe
5 Replies
LEARN ABOUT MOJAVE
cgi::fast
CGI::Fast(3pm) Perl Programmers Reference Guide CGI::Fast(3pm)
NAME
CGI::Fast - CGI Interface for Fast CGI
SYNOPSIS
use CGI::Fast qw(:standard);
$COUNTER = 0;
while (new CGI::Fast) {
print header;
print start_html("Fast CGI Rocks");
print
h1("Fast CGI Rocks"),
"Invocation number ",b($COUNTER++),
" PID ",b($$),".",
hr;
print end_html;
}
DESCRIPTION
CGI::Fast is a subclass of the CGI object created by CGI.pm. It is specialized to work well FCGI module, which greatly speeds up CGI
scripts by turning them into persistently running server processes. Scripts that perform time-consuming initialization processes, such as
loading large modules or opening persistent database connections, will see large performance improvements.
OTHER PIECES OF THE PUZZLE
In order to use CGI::Fast you'll need the FCGI module. See http://www.cpan.org/ for details.
WRITING FASTCGI PERL SCRIPTS
FastCGI scripts are persistent: one or more copies of the script are started up when the server initializes, and stay around until the
server exits or they die a natural death. After performing whatever one-time initialization it needs, the script enters a loop waiting for
incoming connections, processing the request, and waiting some more.
A typical FastCGI script will look like this:
#!/usr/bin/perl
use CGI::Fast;
&do_some_initialization();
while ($q = new CGI::Fast) {
&process_request($q);
}
Each time there's a new request, CGI::Fast returns a CGI object to your loop. The rest of the time your script waits in the call to new().
When the server requests that your script be terminated, new() will return undef. You can of course exit earlier if you choose. A new
version of the script will be respawned to take its place (this may be necessary in order to avoid Perl memory leaks in long-running
scripts).
CGI.pm's default CGI object mode also works. Just modify the loop this way:
while (new CGI::Fast) {
&process_request;
}
Calls to header(), start_form(), etc. will all operate on the current request.
INSTALLING FASTCGI SCRIPTS
See the FastCGI developer's kit documentation for full details. On the Apache server, the following line must be added to srm.conf:
AddType application/x-httpd-fcgi .fcgi
FastCGI scripts must end in the extension .fcgi. For each script you install, you must add something like the following to srm.conf:
FastCgiServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
This instructs Apache to launch two copies of file_upload.fcgi at startup time.
USING FASTCGI SCRIPTS AS CGI SCRIPTS
Any script that works correctly as a FastCGI script will also work correctly when installed as a vanilla CGI script. However it will not
see any performance benefit.
EXTERNAL FASTCGI SERVER INVOCATION
FastCGI supports a TCP/IP transport mechanism which allows FastCGI scripts to run external to the webserver, perhaps on a remote machine.
To configure the webserver to connect to an external FastCGI server, you would add the following to your srm.conf:
FastCgiExternalServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -host sputnik:8888
Two environment variables affect how the "CGI::Fast" object is created, allowing "CGI::Fast" to be used as an external FastCGI server.
(See "FCGI" documentation for "FCGI::OpenSocket" for more information.)
FCGI_SOCKET_PATH
The address (TCP/IP) or path (UNIX Domain) of the socket the external FastCGI script to which bind an listen for incoming connections
from the web server.
FCGI_LISTEN_QUEUE
Maximum length of the queue of pending connections.
For example:
#!/usr/local/bin/perl # must be a FastCGI version of perl!
use CGI::Fast;
&do_some_initialization();
$ENV{FCGI_SOCKET_PATH} = "sputnik:8888";
$ENV{FCGI_LISTEN_QUEUE} = 100;
while ($q = new CGI::Fast) {
&process_request($q);
}
CAVEATS
I haven't tested this very much.
AUTHOR INFORMATION
Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Address bug reports and comments to: lstein@cshl.org
BUGS
This section intentionally left blank.
SEE ALSO
CGI::Carp, CGI
perl v5.18.2 2014-01-06 CGI::Fast(3pm)