Script to move files and Creation of folder structure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to move files and Creation of folder structure
# 1  
Old 12-12-2017
Script to move files and Creation of folder structure

We are receiving few zipped files in one location say : apple/oranges/incoming

All .zip files are placed here in incoming folder.

So few of the files are password encrypted.

There are only 10 zipped files, so we are planning to create a script which will pick that zip file from incoming location and place the files in orange/ongoing.


Before placing the zip files in Ongoing we need to create folders such as 101/801/SAW(we can hard code the folder structure) and then place the file in SAW.
To unzip the files we provide password and then remove the zipped file.

Here is the code I have tried:

Code:
#!/bin/sh
root=$(/apples/oranges/Incoming/sx15440101_ope)
for file in $root
do
srcdir=$(/apples/oranges/Ongoing/)
dir=$(mkdir -p 809/116/RAW)
password=$(echo "$file" | awk '{print substr($1, 1, 10)}')
cd "$srcdir" || exit
cp "$file" "$dir"
unzip -P "$password" -0 "$file"
done

Also there are other files which are not password encrypted they just need to be placed in ongoing, create the folder and unzipped.


Here is my environment:

Code:
$ uname -a
Linux sosuhenhl01 2.6.32-696.10.1.el6.x86_64 #1 SMP Wed Jul 19 08:18:21 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
$ ps
  PID TTY          TIME CMD
15392 pts/0    00:00:00 ps
41789 pts/0    00:00:00 bash
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
$ ksh --version
-bash: ksh: command not found
$ sh --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
There is NO WARRANTY, to the extent permitted by law.
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 31  2017 /bin/sh -> bash
$ awk --version
GNU Awk 3.1.7
Copyright (C) 1989, 1991-2009 Free Software Foundation

As the password varies for each file I am trying to individual script for each file which is easy for us to setup the load.
# 2  
Old 12-13-2017
Quote:
Originally Posted by Sidhant
We are receiving few zipped files in one location say : apple/oranges/incoming

All .zip files are placed here in incoming folder.

So few of the files are password encrypted.

There are only 10 zipped files, so we are planning to create a script which will pick that zip file from incoming location and place the files in orange/ongoing.


Before placing the zip files in Ongoing we need to create folders such as 101/801/SAW(we can hard code the folder structure) and then place the file in SAW.
To unzip the files we provide password and then remove the zipped file.

Here is the code I have tried:

Code:
#!/bin/sh
root=$(/apples/oranges/Incoming/sx15440101_ope)
for file in $root
do
srcdir=$(/apples/oranges/Ongoing/)
dir=$(mkdir -p 809/116/RAW)
password=$(echo "$file" | awk '{print substr($1, 1, 10)}')
cd "$srcdir" || exit
cp "$file" "$dir"
unzip -P "$password" -0 "$file"
done

Also there are other files which are not password encrypted they just need to be placed in ongoing, create the folder and unzipped.


Here is my environment:

Code:
$ uname -a
Linux sosuhenhl01 2.6.32-696.10.1.el6.x86_64 #1 SMP Wed Jul 19 08:18:21 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
$ ps
  PID TTY          TIME CMD
15392 pts/0    00:00:00 ps
41789 pts/0    00:00:00 bash
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
$ ksh --version
-bash: ksh: command not found
$ sh --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
There is NO WARRANTY, to the extent permitted by law.
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 31  2017 /bin/sh -> bash
$ awk --version
GNU Awk 3.1.7
Copyright (C) 1989, 1991-2009 Free Software Foundation

As the password varies for each file I am trying to individual script for each file which is easy for us to setup the load.
First, you talk about creating a directory called SAW, yet in your code it is RAW. Second, you appear to be extracting the password from the filename. Is that correct? How do you know when a file is encrypted and when it is not?

There is so much wrong with the script as presented I don't know where to begin.
  • Using $() inappropriately
  • mkdir does not print anything do dir is empty
  • How do you know when a file is password protected? Your script appears to expect them all to be
  • Is the password in the filename?
  • You are not putting anything into the ongoing directory.

I'm assuming
Code:
root=$(/apples/oranges/Incoming/sx15440101_ope)

is to set root to /apples/oranges/Incoming/sx15440101_ope, but the shell will expect sx15440101_ope to be an executable.
Similarly,
Code:
dir=$(mkdir -p 809/116/RAW)

will result in a null value for the variable dir.

I don't know zip so I don't know what this is doing:
Code:
unzip -P "$password" -0 "$file"

Are you trying to unzip the file or replace it with a decrypted version?

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Parallel move keeping folder structure along with files in it

The below will move all the files in the directory dir to the destination using parallel and create a log, however will not keep them in the directory. I have tried mkdir -p but that does not seem to work or at least I can not seem to get it (as it deletes others files when I use it). What is the... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

How to move the files older than x days with similar directory structure?

Hello, I need to move all the files inside /XYZ (has multi-depth sub directories) that are older than 14 days to/ABC directory but with retaining the SAME directory structure. for example: /XYZ/1/2/3/A/b.txt should be moved as /ABC/1/2/3/A/b.txt I know about find /XYZ -type f -mtime +14... (3 Replies)
Discussion started by: prvnrk
3 Replies

4. Shell Programming and Scripting

Move files from Space Folder to other folder

I want to move a folder with spaces from one folder to another. I have two folders like this, 1).RT_032-222 -4444-01/ 2). RT_032-555 -7777-01/ I want to move files from 2 to 1 through shell script.Here I want to assign this like a user defined variable like as Source branch... (2 Replies)
Discussion started by: kannansoft1985
2 Replies

5. Linux

Create folder by script & move files in it

Hi Team, I have over 1 lakh pdf files. I want to create folders like Disk-1, Disk-2 ..... & want to move 3000 pdfs per folder. Can i do it by script? Please help me. Thanks & Regards Parag Nehete (4 Replies)
Discussion started by: paragnehete
4 Replies

6. Shell Programming and Scripting

Script to move files with similar names to folder

I have in directory /media/AUDIO/WAVE many .mp3 files with names like: my filename_01of02.mp3 my filename_02of02.mp3 Your File_01of06.mp3 Your File_02of06.mp3 etc.... In the same directory, /media/AUDIO/WAVE, I have many folders with names like 9780743579490 9780743579491 etc.. Inside... (7 Replies)
Discussion started by: glev2005
7 Replies

7. Shell Programming and Scripting

Move files & folder structure

Hey, this might be a really basic question, but I'm new to Unix scripting. I'm trying to find a command to replicate a file structure from one location to another & move the actual files contained in the base directories, i.e. I have this structure - home/temp/test/dir1/ ... (3 Replies)
Discussion started by: SOCLA_CELT
3 Replies

8. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

9. Shell Programming and Scripting

move files and retain subdir structure

hi: I have some files like this folder1/recording1.mp3 folder1/docs/budget.doc folder2/others/misc.mp3 folder3/others/notes.doc all this folders and files are under the mp3 folder. I would like to move just the mp3s to another folder but retain the subdir structure i have. So if... (4 Replies)
Discussion started by: jason7
4 Replies

10. Shell Programming and Scripting

Move files based on year of creation

Hi All, I have a directory which has crores of files since from 2003 till now. I want to move only the 2003 files to another directory. Please help. Thanks (2 Replies)
Discussion started by: IHK
2 Replies
Login or Register to Ask a Question