LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   "Invalid Command" error running .sh script (https://www.linuxquestions.org/questions/linux-newbie-8/invalid-command-error-running-sh-script-892238/)

nixanwin 07-17-2011 10:51 PM

"Invalid Command" error running .sh script
 
So what does it mean when I can run this command as root successfully from the command line (it will find all user.xml and zip):

find /mnt/user/ -maxdepth 3 -name user.xml -type f | zip -rp filename.zip -@

But when I add it to a script (.sh) I get the error below:

(contents of xml-backup.sh)
#!/bin/bash
filename=`date +%Y-%m%d-%H:%M`
find /mnt/user/ -maxdepth 3 -name user.xml -type f | zip -rp $filename.zip -@


Error:
)ip error: Invalid command arguments (no such option

Any thoughts?

paulsm4 07-17-2011 10:58 PM

Two suggestions:

1. I'm not at all sure about the "-@" syntax.
Please consider writing a test script with a couple of sample files to see if it works.

2. Often, "invalid command" or "command not found" errors come from:
a) writing the shell script in Windows
b) running the script in Linux - without stripping DOS/Windows "CRLF" from the file first
Please look at your file in "vi" ("vi -b") and check for any funny "^M" characters in your file.

choogendyk 07-18-2011 07:29 AM

When I look at the Linux man page for zip, I don't see the -p option. Your error message in fact indicates "no such option", but you seem to have clipped the error message or something when you entered it above, since it doesn't indicate which option it is complaining about.

grail 07-18-2011 09:19 AM

And not that it should cause an issue, but you really should test the 'filename' setting on the command line to, so as to confirm it does not cause issues as the 2 lines are not the same.

nixanwin 07-18-2011 10:49 AM

Thank you all for the replies. Per paulsm4, It was because I copied the script to notepad++ in Windows to edit - Doh! I re-created the script using nano and it seems to run fine. Noob mistake I guess but learning :-)


All times are GMT -5. The time now is 11:45 PM.