Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Simple find command

SOLVED
Go to solution
Paul Sperry
Honored Contributor

Simple find command

Greetings all,

I have a simple script to copy oracle dumps
across a nfs mount to another server that is offsite. Here is is.

#!/bin/sh
DATE=$(date +%m%d)0700
touch -t $DATE /tmp/reffile
find /usr/local/dumps -type f -name *.gz -newer /tmp/reffile -exec cp {} /offsite_mnt \;
sleep 5
rm -f /tmp/reffile


The find command is all on one line.
In the actual script I use full paths for all commands. but when I run it It comes back with:

/usr/bin/find: paths must precede expression
Usage: /usr/bin/find [path...] [expression]


Any Ideas ? I am loosing hair over this.

TIA
Paul
11 REPLIES
Rick Garland
Honored Contributor
Solution

Re: Simple find command

I put double quotes around the wildcard ("*.gz") and I also put the -name before the -type

Paul Sperry
Honored Contributor

Re: Simple find command

Thanks Rick that did it.
I guess linux find is slightly different than HP-UX. Thanks again and happy hollidays
Ivan Ferreira
Honored Contributor

Re: Simple find command

The -name test takes only one argument. In your command line, the shell is expanding the *s* into more than one argument before the find command is run.

Therefore you get the error you see. You should either escape any shell metacharacters in the -name argument or enclose that argument in quotes.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Paul Sperry
Honored Contributor

Re: Simple find command

Ivan,

Thanks for the clearification.
Happy Hollidays

Paul
Paul Sperry
Honored Contributor

Re: Simple find command

Hey all,

Well the script works fine when I run it from the command line. But when I try to schedual it in cron it doesn't work. No clues in the cron log or messages file.
the cron log shows it runs for 6 seconds
(sleep 5 + 1 sec) so my guess is the find is not working. Any ideas

TIA
Paul
Alexander Chuzhoy
Honored Contributor

Re: Simple find command

you didn't provide us the crontab file,
anyway I suggest you to provide the full path of an executable in crontab.This executable would be a bash script with one command.In your case the find command.If it works-great!Otherwise try other simpler commands like "touch /tmp/filename". Isolate the problem in other words...
Hope it helps.
Ivan Ferreira
Honored Contributor

Re: Simple find command

Cron jobs reports any errors that went to stdout and stderr by mail. You can configure in the crontab file the variable MAILTO= to indicate who should receive the mail, by default is the user.

Another way to debug is to redirect the ouput of the command to a log file, if this script is called clean.bash, configure your cron to run to something like this:

5 * * * * /usr/local/sbin/clean.bash > /var/log/clean.log 2>&1
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Paul Sperry
Honored Contributor

Re: Simple find command

Hey guys,

Thanks for the help, I am more of a HP-UX guy than a linux person. At any rate I finally got it working. For some reason I had to start and stop cron in order to get the log file to be created and the script worked. (0 byte logfile) I decided to stop logging the job and the thing quit working so I stopped and started cron again and the job worked again. So it seems that any time I make any changes to my cron jobs I have to restart crond. Something I never have to do in HP-UX. Or maybe my Linux server is flakey?

Once again thanks for your help
And Happy New Years to All.

Paul
Ivan Ferreira
Honored Contributor

Re: Simple find command

I can warranty that you don't have to restart cron at any modifications. Are you editing using crontab -e? Do not edit directly the file in /var/spool/cron.

You only need to restart cron when you clean the cron log file (/var/log/cron), so cron can write to the file again.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Paul Sperry
Honored Contributor

Re: Simple find command

Ivan,

Yes I was using crontab -e to edit my cron jobs. But honestly any time I changed my job it quit working untill I restarted crond.
Makes no sence to me but I am glad to hear this isn't a "normal" thing to have to do.
Perhaps I am behind on patches. We are mostly a HP-UX and windows operation but are favoring Linux over Windows for any new servers.

Thanks again
Happy New Years To All


Paul
Muthukumar_5
Honored Contributor

Re: Simple find command

Try as,

#!/bin/sh

# Script
touch -t $(date +%m%d)0700 /tmp/reffile

# Will go to cron log
echo "Operation is Started :)"

for file in `find /usr/local/dumps -name "*.gz" -type f -newer /tmp/reffile`
do
cp ${file} /offsite_mnt;
done
sleep 1
rm -f /tmp/reffile

# Will go to cron log
echo "Operation is completed :)"

#END
exit 0

Edit crontab -e as,
5 * * * * path to script

and monitor cron log and post the result.

-Muthu
Easy to suggest when don't know about the problem!