Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Is it Possible to combine these two loops into one? Post 303009922 by BG_JrAdmin on Friday 22nd of December 2017 07:26:19 AM
Old 12-22-2017
Is it Possible to combine these two loops into one?

Hi there! I created a script to upload some files that are in two separate directories at the source, and need to go to two separate directories at the destination, so I made two loops. I was hoping for some suggestions how I could combine this into one loop?



Code:
# START of PROGRAM
#
#     Get the "Delete / Removal" files and Upload them.
#
for DELFILES in `ls $SOURCEDELDIR`
   do
      echo $TODAY >> $LOGFILE.$TODAY
          $SFTPCMD -oIdentityFile=$SFTPKEY $SFTPUSER@$SFTPURL >> $LOGFILE.$TODAY <<ENDSCRIPT
            mput $SOURCEDELDIR/$DELFILES $SFTPDELDIR
          exit
ENDSCRIPT
   done
#
#    Get the "Update / Extraction" files and Upload them.
#
for UPTFILES in `ls $SOURCEUPTDIR`
   do
      echo $TODAY >> $LOGFILE.$TODAY
           $SFTPCMD -oIdentityFile=$SFTPKEY $SFTPUSER@$SFTPURL >> $LOGFILE.$TODAY <<ENDSCRIPT
             mput $SOURCEUPTDIR/$UPTFILES $SFTPUPTDIR
           exit
ENDSCRIPT
   done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

While Loops

I'm trying to create a loop that will prompt the user for 15 values, not forcing them to enter all 15. If the user enters through one or more of the prompts the null value needs to be converted to 0, otherwise set the parameter = to the value entered: ex. Please enter file no #1: 17920 ... (4 Replies)
Discussion started by: vdc
4 Replies

2. UNIX for Dummies Questions & Answers

two loops

Hi, how can I use "for" to have two loops : this is my script : for i in (A B C) do for j in (a b c) do echo $i$j done done #End I want to print out Aa Ab Ac .... But I have error message : syntax error at line 1 : `(' unexpected Many thanks before. How should I use "for" ?? (2 Replies)
Discussion started by: big123456
2 Replies

3. Shell Programming and Scripting

while loops

Hi I've a file like so: Now, I want to read my file and take ex. the Media ID and the Type for each groups of Media (Media1,Media2,...,Media(n): cat /tmp/file|\ while read FILE do while $(FILE|cut -d: -f1)=Media$i do #here will be some test, ex: #if Media ID < 23 ... (4 Replies)
Discussion started by: nymus7
4 Replies

4. UNIX for Dummies Questions & Answers

For Loops

Hi everyone, I have a question regarding for loops. I am writing a BASH shell script that will contain multiple loops. These loops all involve looping with a count: for (( a=0; a <=10; a++ )); do echo $a done If none of my multiple loops relate to each other throughout the script,... (3 Replies)
Discussion started by: msb65
3 Replies

5. Shell Programming and Scripting

Loops

Hi All, I want to execute a script the number of times a user enters. Please can you advise on hor can I do the same. Many Thanks, Shazin (4 Replies)
Discussion started by: Shazin
4 Replies

6. UNIX for Dummies Questions & Answers

loops with tr

Hello, I'm not sure if this is more appropriate for the 'unix for dummies' or the 'unix for experts' forum because I'm new to this forum and this is the second topic I've discussed, but if you could let me know which one was more appropriate for something like this, please do! So in tr (an... (2 Replies)
Discussion started by: juliette salexa
2 Replies

7. Shell Programming and Scripting

loops

Hi All I have some directories on our server which are containing .csv files. i need to print value of cell "B2" from those csv files. Please advise. I have tried head command as example: head -2 */Book_Collection_Report_1_-_Collection_Requests_trials.csv | sed -n "3p" | awk -F","... (4 Replies)
Discussion started by: yash1978
4 Replies

8. Shell Programming and Scripting

Loops

Hi All, I am very new to Shell scripting. I read basic scripting manual. But i didn't understand the code. Please tell the meaning of the below code: while getopts "F:f:R:r:C:c:" opt 2>/dev/null do case ${opt} in F|f) FREQUENCY_MODE=$OPTARG;; ... (3 Replies)
Discussion started by: pdathu
3 Replies

9. UNIX for Advanced & Expert Users

Help with loops?

I'm trying to understand better the while and until loops, can someone help me with this example? #!/bin/bash # Listing the planets. for planet in Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto do echo $planet # Each planet on a separate line. done echo; echo for... (3 Replies)
Discussion started by: jose2802
3 Replies

10. UNIX for Dummies Questions & Answers

Need help with for loops

Why wont my for statements work? Im trying to get this script to swich to a user an if you put in a start/stop/or restart paramater to do just that for each user. I commented out the actual start/stop actions to test it just by using echos and not do anything hasty in the environment but it... (0 Replies)
Discussion started by: LilyClaro
0 Replies
SYSTEMD-TMPFILES(8)						 systemd-tmpfiles					       SYSTEMD-TMPFILES(8)

NAME
systemd-tmpfiles, systemd-tmpfiles-setup.service, systemd-tmpfiles-setup-dev.service, systemd-tmpfiles-clean.service, systemd-tmpfiles- clean.timer - Creates, deletes and cleans up volatile and temporary files and directories SYNOPSIS
systemd-tmpfiles [OPTIONS...] [CONFIGFILE...] systemd-tmpfiles-setup.service systemd-tmpfiles-setup-dev.service systemd-tmpfiles-clean.service systemd-tmpfiles-clean.timer DESCRIPTION
systemd-tmpfiles creates, deletes, and cleans up volatile and temporary files and directories, based on the configuration file format and location specified in tmpfiles.d(5). If invoked with no arguments, it applies all directives from all configuration files. If one or more filenames are passed on the command line, only the directives in these files are applied. If only the basename of a configuration file is specified, all configuration directories as specified in tmpfiles.d(5) are searched for a matching file. OPTIONS
The following options are understood: --create If this option is passed, all files and directories marked with f, F, w, d, D, p, L, c, b, m in the configuration files are created or written to. Files and directories marked with z, Z, m have their ownership, access mode and security labels set. --clean If this option is passed, all files and directories with an age parameter configured will be cleaned up. --remove If this option is passed, all files and directories marked with r, R in the configuration files are removed. --boot Also execute lines with an exclamation mark. --prefix=PATH Only apply rules that apply to paths with the specified prefix. This option can be specified multiple times. --exclude-prefix=PATH Ignore rules that apply to paths with the specified prefix. This option can be specified multiple times. --help Prints a short help text and exits. It is possible to combine --create, --clean, and --remove in one invocation. For example, during boot the following command line is executed to ensure that all temporary and volatile directories are removed and created according to the configuration file: systemd-tmpfiles --remove --create EXIT STATUS
On success, 0 is returned, a non-zero failure code otherwise. SEE ALSO
systemd(1), tmpfiles.d(5) systemd 208 SYSTEMD-TMPFILES(8)
All times are GMT -4. The time now is 12:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy