How to remove invalid characters from filenames?

One way would be with sed: mv ‘file’ $(echo ‘file’ | sed -e ‘s/[^A-Za-z0-9._-]/_/g’) Replace file with your filename, of course. This will replace anything that isn’t a letter, number, period, underscore, or dash with an underscore. You can add or remove characters to keep as you like, and/or change the replacement character to anything … Read more

Log all commands run by admins on production servers

Update: 2 more things that have popped up in the comments and in follow-up questions: Using auditd this way will dramatically increase your log volume, especially if the system is heavily in use via commandline. Adjust your log retention policy. Auditd logs on the host where they are created are just as secure as other … Read more

What does passing the -xe parameters to /bin/bash do

If you read the man page for bash you’ll find the following at the top of the OPTIONS section: All of the single-character shell options documented in the description of the set builtin command can be used as options when the shell is invoked. In addition, bash interprets the following options when it is invoked… … Read more

How can I fully log all bash scripts actions?

I generally put something similar to the following at the beginning of every script (especially if it’ll run as a daemon): #!/bin/bash exec 3>&1 4>&2 trap ‘exec 2>&4 1>&3’ 0 1 2 3 exec 1>log.out 2>&1 # Everything below will go to the file ‘log.out’: Explanation: exec 3>&1 4>&2 Saves file descriptors so they can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)