LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Help with "find" command in backup/zip script (https://www.linuxquestions.org/questions/linux-general-1/help-with-find-command-in-backup-zip-script-862503/)

nixanwin 02-13-2011 10:17 PM

Help with "find" command in backup/zip script
 
Hi, I am fairly new to scripting and I am trying to write a script that finds and zips a file named file1.xml from multiple sub-directories. So basically I want to find them and zip them all together. The disk directory structure is as follows:

/mnt/data/user_name1/db/file1.xml
/mnt/data/user_name2/db/file1.xml
(etc, etc where user_name varies)

This is what I have so far, but I keep getting an error relating to the -name command.

filename=`date +%d%m%Y-%H:%M`
find /mnt/data/ -name file1.xml -maxdepth 2 -type d | zip -rp $filename.zip -@


I keep getting the following error but don't know how to fix it. Is what I am trying to do even possible?

find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

Thank you in advance for your patience

Dark_Helmet 02-13-2011 11:17 PM

Quote:

Originally Posted by nixanwin
I keep getting the following error but don't know how to fix it. Is what I am trying to do even possible?

find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

You're not getting an error. As the message says, you're getting a "warning." Typically, a warning does not stop the program, but alerts you that you may not get the results you expect. This warning tells you that the -maxdepth option should be placed before -name on the command line. It also says that, in the case of -maxdepth, it will have the desired effect regardless.

In a nutshell, the program is telling you the form of the command is not what the developers expect--certain command line switches can have different effects depending on where they are placed on the command line.

That said, I think your command is wrong for a different reason. You say you are looking for a "file" named "file1.xml" but your find command is looking for a directory (-type d). I think you probably intended "-type f"

nixanwin 02-21-2011 10:00 AM

Sorry for the delay! I tried change the "d" to and "f" and get the following error. For the record, I'm open to a different way to accomplish this. I'm just learning this stuff...

find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.


)ip error: Invalid command arguments (no such option:
: command not foundes.sh: line 9:


Any help is appreciated. I'm open to pay for a fix if someone want's to PM me. Thanks

Dark_Helmet 02-21-2011 02:03 PM

Ok, would it be possible to post the script here?

The message you copy-pasted this last time included some more info: there's more going on than just a warning from find. There's a parsing error:

Quote:

)ip error: Invalid command arguments (no such option:
: command not foundes.sh: line 9:
And in my experience, that typically means there could be a mistake as simple as a missing space/semicolon or how the script variables are being used or referenced.

So please, if you can, post the script.

nixanwin 02-21-2011 11:44 PM

Got it working. I'm not sure what the problem was exactly. Thank you for pointing out the "f" switch

filename=`date +%d%m%Y-%H:%M`
find /mnt/data/ \
-name Profile.xml -maxdepth 3 -type f | zip -rp $filename.zip -@


All times are GMT -5. The time now is 04:33 PM.