I can't tell you where your problem is yet, but here are some suggestions from looking at the code.
0) As grail mentioned, please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
1) Clean,
consistent formatting makes code more readable and easily debuggable. Be liberal with whitespace, both horizontal and vertical. Indent all your sub-commands evenly and separate logical sections with empty lines. Never just line everything up on the left edge.
Many scripters also feel that it's better to place the "
do/then" keywords on the same line as the "
for/while/until/if" keywords, as they are not separate commands but the closing indicators for the test block, and so are paired directly with the opening keyword. Putting them together on one line thus more clearly separates the outside block from the inside block.
Scripting With Style
2) It's a
really bad idea to hard-code user names and passwords into a script. A better option would be to store them in a separate "credentials" style file, readable only by the user running the script, and source that file into it.
Code:
#this is the password file
#OSCommerce User to use for update operation
user="administrator"
#OSCommerce password to use for update operation
pass="reallygoodpasswordlol"
Code:
#this imports the password file if found.
if [[ -r "$HOME/passwordfile ]]; then
. "$HOME/passwordfile"
else
echo "Password file not found or not readable. Exiting."
exit 1
fi
Or you could set it up to ask the user for them directly.
3) You use the exact same
date command over and over in the script. Why not just run it
once and save the value into a variable to use after that?
4)
$(..) is highly recommended over `..`.
5) When you have a long string of options for a command, you can use an
array to set them up ahead of time.
Code:
curlopts+=( -v --cookie cookies.txt --cookie-jar cookies.txt )
curlopts+=( -D Headers.txt --user-agent Mozilla/4.0 -u "$user:$pass" )
curlopts+=( --data "username=$user&password=$pass" )
curlopts+=( "$admin_URL/login.php?action=process" )
curl "${curlopts[@]}"
Also consider setting up
functions for complex or oft-repeated commands. In addition to making the code more organized, they can also help to keep the script's running environment less cluttered, by setting to
local variables not needed globally.
6)
All strings with variables like this should be quoted. Just leave them off the globbing patterns and the like.
Code:
#wrong
# rm $local_dir/temp/$csv_filename*
#right
rm "$local_dir/temp/$csv_filename"*
It's
vital in scripting to understand how the shell handles arguments and whitespace. Many script errors come down to improper quoting:
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
7) Learn the power of
printf.
Code:
while IFS=$'\t' read -r -a myArray ; do
printf '%s\n' "${myArray[@]:0:7}"
done < saved-cookies
That's about it for now. Good luck!