"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? |
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. |
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.
|
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.
|
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. |