Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Create Year directory, date subdirectory and archive the file Post 302150786 by Lakris on Wednesday 12th of December 2007 04:42:12 PM
Old 12-12-2007
Well, there are a few things in Your script that I find a bit strange. Do You want to call this script for each file You want to process? Why do You want nanoseconds if they are always static? Don't You just want to check for existence of a file? And there are a few other syntax errors as well (for example DIR is not defined) and some things will work with absolute paths but not relative.

Anyway, strip off some stuff (to make it shorter) and get to the essence of if, try the following. Unless it is important to know if a directory exist or not, just create it when You need it. An example:

Code:
if [ ! $# -eq 3 ]
then
  echo "Usage: $0 <INPUT DIRECTORY> <DEST DIRECTORY> <FILE NAME> "
  exit 1
fi

FILE_SUFFIX=`date '+%Y-%m-%d-%H.%M.%S.000000'`
FINAL_DEST_DIR=$2/`date +%Y`/`date +%Y%m%d`

if [ -f "$1/$3" ] 
then
    echo "File $3 Found in $1, moving it to $FINAL_DEST_DIR/$3.$FILE_SUFFIX"
    mkdir -p $FINAL_DEST_DIR
    mv $1/$3 $FINAL_DEST_DIR/$3.$FILE_SUFFIX
else
    echo "\tError: File $3 Not Found"
fi

Maybe it can help You a bit on the way.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to calculate file's size in directory and subdirectory

Hi, I have written one script to calculate total space of all file in one directory, ignoring subdirectory, it works fine. Now, I've been trying to calculate all files which includes files in any subdirectories. I use recursive function to do this, but it can work only if there is only one... (4 Replies)
Discussion started by: KLL
4 Replies

2. UNIX for Dummies Questions & Answers

create a archive of old file

i need a script which will create a archive of the files older than 10 days........ (2 Replies)
Discussion started by: jayaramanit
2 Replies

3. UNIX for Dummies Questions & Answers

create tar archive without preserving directory structure?

I am adding some individual files to a tar archive and would like them to be added to the archive without any directory hierarchy, even though the files themselves exist in levels of hierarchy. Unfortunately, tar seems to always preserve the directory hierarchy when it adds the files. Here is... (2 Replies)
Discussion started by: Special_K
2 Replies

4. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

5. Shell Programming and Scripting

Sum of file size in directory / subdirectory

Hi , I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level .. #!/bin/ksh FNAME='.pdf' S_PATH=/abc/def/xyz find $S_PATH -exec ls -lad... (4 Replies)
Discussion started by: Vaddadi
4 Replies

6. Shell Programming and Scripting

How can i find a word inside a file from a directory and it's subdirectory ?

Suppose i have a word "mail". I have to search this word in all files inside a directory and it's sub-directories. It will also search in all hidden directory and sub-directories. If it finds this word in any file it will list that file. How can i do this with perl/ruby/awk/sed/bash or... (9 Replies)
Discussion started by: cola
9 Replies

7. Shell Programming and Scripting

Move all files not in a directory into a subdirectory named for each given file

Hi Everyone! Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file. Any ideas? Thank you! (1 Reply)
Discussion started by: DanTheMan
1 Replies

8. Shell Programming and Scripting

Searching File in Directory and all Subdirectory and Delete

Hi All, My directory structure is like Directory1 SubDirectory1 SubDirectory2 SubDirectory3 I have main directories and subdirectories underneath. I want to write a shell script where I will be passing file name as a parameter, Now I want to find all the files in Directory1... (19 Replies)
Discussion started by: John William
19 Replies

9. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

10. Shell Programming and Scripting

Create file every year and log data to it

Hi there, Here is what I currently have and trying to come up with a logic to automatically append logs to a respective year file. The log files might get generated everyday or any other day, irrespective of which I want to copy all of the logs for that year into one file /tmp/<year>.log and then... (4 Replies)
Discussion started by: mbak
4 Replies
mread(1)						      General Commands Manual							  mread(1)

NAME
mread - mtools utility to perform a low level read (copy) of a DOS file to UNIX SYNOPSIS
mread [-tnm] msdosfile unixfile mread [-tnm] msdosfile [msdosfiles...] unixdirectory OPTIONS
Preserves the file modification time. Specifies that a warning is not issued when an existing file is specified as the target file. If this option is not specified, the mread command verifies whether or not to overwrite an existing file. Specifies a text file transfer. Line terminators are converted to the appropriate format. DESCRIPTION
The mread command copies the specified DOS file to the named UNIX file, or copies multiple DOS files to the named UNIX directory. DOS subdirectory names that contain the '/' or '' separator are supported. If you use the '' separator or wildcards, you must enclose file names in quotes to protect them from the shell. The mcd command can be used to establish the device and the current working directory (relative to DOS), otherwise the default is A:. RESTRICTIONS
Unlike DOS convention, the destination directory may not be omitted. EXIT STATUS
The following exit values are returned: Success. Failure. ENVIRONMENT VARIABLES
The following environment variables affect the execution of mread: If set, this variable names the file that contains the name of the cur- rent mtools working directory as established by the mcd command. If this variable is not set, the file $HOME/.mcwd is used. FILES
Contains the name of the current mtools working directory as established by the mcd command. If this file does not exist, the default mtools working directory is A:. Executable file SEE ALSO
Commands: dos2unix(1), mcd(1), mcopy(1), mdiskcopy(1), mtools(1), mtype(1), mwrite(1), unix2dos(1) mread(1)
All times are GMT -4. The time now is 08:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy