Shell Script, Copy process using find.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script, Copy process using find.
# 1  
Old 06-11-2010
Shell Script, Copy process using find.

Ok, so here is what I am looking for..
Shell script that uses find to look for one days worth of data using the modified date and then copies only those files to a specified directory.

I figured I could use grep and the find command to do this. It seems to work just fine from what I can tell... However....

When the file isn't created for that day and my shell script runs (cron job) this is the error I get. I was hoping to remove that error message as I dont need to know if there isnt any files. However, I created a simple echo just to test the functionality and I am still getting an error.

Here is the script.
Code:
#!/usr/bin/ksh
#The below specifies daily RX and RS files from the T00010 Folder
#It pulls only files that are one day old
#Created by: Techjunky
file1=`find /opt/gp00/data/T00010/CYC_REPORTS -mtime 0 | egrep -i 'RX010453'`
file2=`find /opt/gp00/data/T00010/CYC_REPORTS -mtime 0 | egrep -i 'RS010453'`
#The below script copies RX and RS files within the T00010 folder if they exist
#This process is used for EC2000 Reporting for customer 10453.  There is a windows scheduled task on WNP4694 to copy the files to a specified folder.
if [$file1]; then
  cp $file1 /opt/gp00/data/T00010/CYC_REPORTS/10453/RX/
else
  echo RX file does not exist!
  if [$file2]; then
    cp $file2 /opt/gp00/data/T00010/CYC_REPORTS/10453/RS/
  else
    echo RS file does not exist!
  fi
fi
exit 1

Here is the error message I get when there aren't files for that day.
Code:
./CYC_REPORTS_10453.sh[9]: []:  not found
RX file does not exist!
./CYC_REPORTS_10453.sh[13]: []:  not found
RS file does not exis

t!

basically my script runs, but there is no file there so I get the error message... It makes perfect sense why I am getting that error mesage I just cant think of the logic so this wont happen. Just getting the RX and RS echo messages would be enough.

Last edited by Franklin52; 06-11-2010 at 06:17 PM.. Reason: Please indent your code and use code tags
# 2  
Old 06-11-2010
Change
Code:
if [$file1]; then

to
Code:
if [ x$file1 != "x" ]; then

and
Code:
if [$file2]; then

to
Code:
if [ x$file2 != "x" ]; then

Space is required here.
# 3  
Old 06-11-2010
First, try spacing things out. Do

if [ $file1 ]

and

if [ $file2 ]

and verify that the square brackets aren't being treated as content in the condition. If that doesn't help, try

if [ -n $file1 ]

and

if [ -n $file2 ]

and see if that works.

(I'm a bash guy, not a ksh guy, so I could be way off, here.)

dafydd
# 4  
Old 06-11-2010
Spacing the brackets out worked. Thanks bartus11!
# 5  
Old 06-11-2010
Ok Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to find out process name that are running for last 10 days.

Hi all, As i am new to shell script.Please help me to write a Shell script to find out process name that are running for last 10 days. Thank's in advance. (8 Replies)
Discussion started by: manas_1988
8 Replies

2. Shell Programming and Scripting

Writte a script to copy the files older than 7 days using find and cp

Hi I'm trying to writte a script (crontab) to copy files from one location to another... this is what i have: find . -name "VPN_CALLRECORD_20130422*" | xargs cp "{}" /home/sysadm/patrick_temp/ but that is not working this is the ouput: cp: Target... (5 Replies)
Discussion started by: patricio181
5 Replies

3. Shell Programming and Scripting

Shell Script to find out if a process is running on any all machines

Hi All, I have been a guest visitor from a long time and this forum is wonderful. I finally am a member of this forum too, so i am here stuck with a shell script that i was trying to write My requirement is that i should be able to create a shell script which will check if a process is running on... (3 Replies)
Discussion started by: Rex0226
3 Replies

4. Shell Programming and Scripting

shell script to find a process by name and kill it

hi, Am a newbie to unix and wasnt able to write script to my requirement. I need a shell script, which should find a process by name and kill it. For eg: let the process name be "abc". I have different processes running by this name(abc), so should kill them all. Condition would be: if... (7 Replies)
Discussion started by: fop4658
7 Replies

5. Shell Programming and Scripting

find and copy script trouble

Hi guys First thing to say is that I am entirely new to Shell Scripting and am trying to write a script to do something I thought would be relatively simple, but has escaped me. Essentially, I want to take file name information from a list, find the files listed and then copy the results into... (0 Replies)
Discussion started by: acheron
0 Replies

6. Shell Programming and Scripting

Perl Script to find & copy words from Web.

I need to write a perl script to search for a specific set of numbers that occur after a series of words but before another. Specifically, I need to locate the phrase today at the summit, then immediately prior to the words tonnes/day copy the number that will be between 100 and 9,999, for example,... (1 Reply)
Discussion started by: libertyforall
1 Replies

7. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

8. Shell Programming and Scripting

Find shell process pid launched throug `at`.

Hi. I was testing some staff and wrote simple script, which only writes date to log every 15 seconds. Like that #1.sh while true;do echo `date` >> 1.log sleep 15 done And than i ran this process with `at -s -f 1.sh now`. And now it is running and i don't know how to catch it. I tryed... (1 Reply)
Discussion started by: kukuruku
1 Replies

9. Shell Programming and Scripting

Help with Find All/Copy Script

Hi Gang, I am an old unix user and just recently returned in the flavor of a Mac. I have tons of pictures in the .orf format and would like to write a script to: Search the Hard drives for that file type Then, depending on date, copy it to a specific folder If there is an exact... (2 Replies)
Discussion started by: jlfx
2 Replies

10. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies
Login or Register to Ask a Question