Need a script find the folders and execute a code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a script find the folders and execute a code
# 1  
Old 08-13-2008
Need a script find the folders and execute a code

I need a script which can search for two files in location /share/point/ which has year and month stamps example 1) Extract200806.txt
2)file_new200805.csv
If these files exists then it should run a code named abc.sas
# 2  
Old 08-13-2008
MySQL can you try this

year=`date "+%Y"`
month=`date "+%m"`
temp=`expr "$month" - 1`
pmonth=`echo "$temp"|awk '{printf "%02d",$1}'`
FILE_PATH=`pwd`
FILE_PATH="/u/fixadma/fix_temp"
TXT_FILE="Extract${year}${month}.txt"
CSV_FILE="file_new${year}${pmonth}.csv"
TXT_COUNT=`find $FILE_PATH -name "$TXT_FILE"|wc -l|awk '{print $1}'`
CSV_COUNT=`find $FILE_PATH -name "$CSV_FILE"|wc -l|awk '{print $1}'`
if [ "$TXT_COUNT" = "1" -a "$CSV_COUNT" = "1" ]
then
## call your program from here
echo "Both the files exist"
fi
# 3  
Old 08-13-2008
Code:
[[ -f /share/point/Extract200806.txt && -f /share/point/file_new200805.csv ]] && /path/to/abc.sas


Last edited by Annihilannic; 08-13-2008 at 03:41 AM.. Reason: typo
# 4  
Old 08-13-2008
The find isn't really correct if there may be subdirectories, and the awk doesn't seem to add any value, since the output from wc is already going to be a single number.

How about this instead?

Code:
test -e path/to/Extract[0-9][0-9][0-9][0-9][0-9][0-9].txt &&
  test -e path/to/file_new[0-9][0-9][0-9][0-9][0-9][0-9].csv &&
  abc.sas

This assumes that the date stamps are always six numbers, and the base file name and extension do not vary. If you have more variation in the file names, please describe what the parameters are.

Last edited by era; 08-13-2008 at 03:45 AM.. Reason: Brilliant minds think alike -- Annihilannic's posting has exactly the same idea
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to loop through folders and execute an existing python script.

I am trying to loop through lots and lots of folders and use the names of the folders to run a Python script which has parameters. E.g. -- setup_refs -n John -f England/London/Hackney/John -c con/con.cnf Normally to run `setup_refs` once from command line it's: `python setup_refs.py -n John... (3 Replies)
Discussion started by: Mr_Keystrokes
3 Replies

2. UNIX for Advanced & Expert Users

Find files in specific folders

Hi Team, I am new to the linux commands and I really need help . I would be really thankful if I can get some inputs. I have below folders in the path "/home/temp" 20170428 20170427 20170429 changes tempI need to get the files generated in the last 15 mins in all the above folders... (4 Replies)
Discussion started by: JackJinu
4 Replies

3. Shell Programming and Scripting

Execute multiple files in multiple folders and also output on same folder

How to execute multiple files in multiple folders and also output to be generated in the same folder? Hello Team, I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
Discussion started by: pushpabuzz
1 Replies

4. Shell Programming and Scripting

Execute script in series of folders

I'm trying to get a script to iterate of an array in bash run a series of commands in those folders. #Folder names folders=(folder1 folder2 folder3) #Common path for folders fold_path="/Users/Rich/Projects/" # For each element array copy script to folder and execute for f in... (2 Replies)
Discussion started by: 3therk1ll
2 Replies

5. UNIX for Dummies Questions & Answers

Find folders that do NOT contain a certain file

I'm no linux guru so any help would be greatly appreciated! I need to output all folders that do not contain a file of a certain extension. Currently I have the following find / ! -name '*.txt' -printf %h\\n This doesn't work because although it finds folders that do not contain *.txt,... (2 Replies)
Discussion started by: hodnov
2 Replies

6. Shell Programming and Scripting

Find empty folders

In current folder, there are many subfolders, subfolder's subfolders... under it. How can I find out the empty folders with no files in it. I only need the top folder list. For example, I have folders like below: a/b/c a/b/x/x.txt a/s a/s/y I need get the folder a/s, but not... (6 Replies)
Discussion started by: rdcwayx
6 Replies

7. Shell Programming and Scripting

Script to find folders with spaces and end of files and directories

Hi I need a script that can search through a set of directories and can locate any file or directory that has a space at the end Filename(space) Foldername(space) I then need to remove that space within the script Hope someone can help thanks in advance Treds (8 Replies)
Discussion started by: treds
8 Replies

8. UNIX for Dummies Questions & Answers

Find and rename all folders with name X.

Is there a command I can use to rename all directories with a certain name to a new name. For instance from my root directory I want to change all folders named '123' to '321' that are in the root directory or any subdirectory. Thanks in advance! (6 Replies)
Discussion started by: mkingrey
6 Replies

9. UNIX for Advanced & Expert Users

find only folders

is there an option in find command to search only for folders (not subfolders). thx (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

10. UNIX for Advanced & Expert Users

Script to Find Diff from two folders

Hi I would like to find the diff between two folders: Ex: Folder:1 html.java go.java ten.java Folder:2html.java go.java ten.java you.java Questions comes: Folder:1 contains a files with old version, know the files were modified and updated with the new version in Folder2. I... (2 Replies)
Discussion started by: gkrishnag
2 Replies
Login or Register to Ask a Question