Tag Info

5

As mentioned by cas in the discussion, you can simplify your loops: for dir in /var/www/html/*/; do if pushd "$dir"; then /usr/local/bin/wp plugin update --all --allow-root && /usr/local/bin/wp core update --allow-root && /usr/local/bin/wp theme update --all --allow-root popd fi done You can also “... 4 alias is like root, so you need to use full server path you can add break flag to rewrite for avoid internal redirect. added without break rewrite will make loop (internal redirect) for process all locations again; but break tell to rewrite do not loop and run current location. I don't think here big difference in performance. Main difference is changing ... 4 The config looks great. However, a few points: If your server responds to both the www and non-www version of the site, just leave a wildcard. So server name should read: server_name *.my-site.com; You shouldn't put your configs in /etc/nginx/conf.d. Instead, place them in /etc/nginx/sites-available and then symlink them (ln -s) to /etc/nginx/sites-... 3 The outer heredoc construct isn't really required. You do not verify that you have command line arguments. You do not assign your command line arguments to the variable domain. You use the variable domain when it is uninitialised. You make a number of assumptions, any one of which could bite you hard. You assume that the nginx package has been installed ... 3 The ngx.var.session_token can be easily setup in store_token_from_uri.lua as follows: ngx.var.session_token = ngx.ctx.args.token or ngx.ctx.args.id or ngx.var.session_token where, the value of ngx.var.session_token will be restored in case both ngx.ctx.args.token and ngx.ctx.args.id are nil. The if-elseif blocks are not required anymore. If you do not ... 2 You need to get into the habit of performing all of your business logic before your start outputting to the browser. Say someone posted bad data and you wanted to redirect to a 403 page using header(). You can't do that now, because you have already started output. Right now your code could also lead to malformed HTML. What happens if$_POST is not set? ...

2

Starting with main(): the signature implies that we accept command-line arguments, but we ignore argc and argv, using the hard-coded HOST_ADDR and HOST_PORT instead. This makes the program less flexible. An improvement would be to use those values as defaults, but allow command-line arguments to override them: const char *server = HOST_ADDR; if (argc &...

2

@cas has already pointed out the most critical issues. I add a few minor points on top of that. Syntax errors A semicolon is missing before the fi on this line and another similar line: if [ "$dbrootp_1" != "$dbrootp_2" ]; then echo "Values unmatched. Please try again." && exit 2 fi Usability The script is not very user-friendly. For example, ...

2

My answer is going to focus on your use of shell functions and global variables. There aren't any actual syntax errors in your script AFAICT, but your misuse of functions in this script is dangerously error-prone. There are two main reasons for using a function in bash (or any language, really). The first is to parameterise a frequently performed ...

2

Shellcheck.net I strongly recommend to start using https://shellcheck.net/. Simply copy-paste your script, and it will tell you many issues with this code. Don't use return outside of functions The return statement only works within functions. You probably meant exit instead: domain="$1" && test -z "${domain}" && exit Variables in ...

2

root The root directive is inherited. You have the same statement in the server block, and repeated in a number of location blocks. Only the first statement is necessary. See this document for details. location ~* ^/static/.*$This can be replaced by the prefix location: location /static/ { ... } The prefix location is more efficient than the regular ... 1 At the very least, use verbose mode so you can see the whole thing at once. Remember to explicitly include whitespace. lineformat = re.compile(r""" (?P<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+ -\s+ -\s+ $(?P<dateandtime>\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})$\s+ \"GET (?P<url>.+?(?=\ http\/1.1")) ... 1 You are putting your server_name to be$domain and www.$domain. What if, someone puts in www.example.com for the script argument? You will thne be serving www.example.com and www.www.example.com. Instead; replace possible www. from the domain variable. domain="${domain#www\.}" Each of your location section has a different indentation. Keep it consistent. ...

1

Good Tying together related commands with && is a good error-avoidance strategy. Trouble The code is not re-entrant because the aliases will keep getting appended every time. This is bad because you can only run or "enter" the code once safely. You could touch file if the aliases are added and use that as a flag. I would create the aliases in ...

1

I compared the two server configurations and the only thing that appears to match between the two is the location ~ \.php\$ directive, as well as the index directive, though in the latter configuration that is under the directive location / Perhaps the common configurations could be put into the file included via include (i.e. fastcgi-php.conf).

1

Error handling The script misses error handling at several places. The downloads could fail or be corrupt, but the script will continue until the end, and finding the failure point can be difficult. Worse, if a failure is quiet enough, it might not even get noticed. Checking the exit code of every single command can be tedious. An alternative is to add ...

1

It is difficult to say by just watching the code lines. (1) You can measure line by line. I wrote a simple class to add a message whenever you want. The render method draws an html table an shows the diff time between each message: http://www.phpclasses.org/package/9282-PHP-Log-and-render-current-script-actions.html (2) If the connect time to mysql is ...

Only top voted, non community-wiki answers of a minimum length are eligible