Mysql SQL in bash one-liner

If you just need a quick way to get some data from a mysql database in your shell (bash), you could do something like this in one line:

mysql -h your.server.edu -u db_username -p`cat /path/to/your/homedir/secretpasswordfile` -e ";use databasename; SELECT tablename.columnname FROM tablename where id like '421111' and something like '1' and option like '23';"; > /tmp/datayouwant.txt; while read i; do echo ";$i";; done < /tmp/datayourwant.txt | sort | uniq

If you don't like to scroll:
-bash-3.2$ mysql -h your.server.edu -u db_username -p`cat /path/to/your/homedir/secretpasswordfile` -e "use databasename; SELECT tablename.columnname FROM tablename where id like '421111' and something like '1' and option like '23';" > /tmp/datayouwant.txt; while read i; do echo "$i"; done < /tmp/datayourwant.txt | sort | uniq

On my server I would then get a list of words/numbers or whatever you might have in the database, which one might want to use further in another script or command:

Dikult
Drupal
DSpace
Mediawiki
Open Journal Systems
Piwik
Postgresql og Mysql
Redhat Enterprise Linux 6 (RHEL6)
Redmine
Solr
Webmail (RoundCubemail)
Wordpress
Xibo

Machform javascript embed form in wordpress post

If one have a form in Machform, one can add the form in a WordPress Post or Page with a simple javascript embed:
[javascript]


[/javascript] Which will give the form: [raw]



[/raw]

Remove branch in remote git repo

If you have a remote git repo, and you want to delete a branch there, you can do:

[bash]
# if you want to delete the branch locally first, do:
git branch -D branchname

#  then also remotely
git push origin –delete branchname
[/bash]

Move a local git repo to a remote repo

Challenge: one have a local git repo on a Linux server where a big bunch of commit’s have been done. Now one want to put all the files and commits on a remote server, for more easier sharing with other.

Here is how it might be done:

First create the remote repo. We use gitolite-admin, where we add typically:
# Explaination of the repo
repo path/to/remote/git/repo
RW+ = adminuser
RW = user1 user2 user3

then,

git push

Now, since there is already a local git repo on the server with commits, we need to switch to the remote repo.
Check that there are no remote:
git remote -v
should not show anything, then:
git remote add origin git@git.uib.no:path/to/remote/git/repo

and possible this one too:

git branch --set-upstream master origin/master

What I had to do now, was to clone the remote repo I created with gitolite-admin in another directory, create a dummyfile, and push it. Then I could push and pull the local repo.
So:
cd /tmp/
git clone git@git.uib.no:path/to/remote/git/repo
vim dummyfile
git add dummyfile
git commit -m "dummyfile" dummyfile
git push origin master

Then:
cd /back/to/the/local/repo/you/want/to/clone/to/remote
git pull
git push origin master

I guess there must be an easier way, but I am no Git master…

Or, one can also do it in this way:

cd folder/
git init
# make a lot of files, add, commit and so on..
# REMOTE GIT REPO AVAILABLE AT git@something.url.edu:sys/path/remoterepo.git
# First push files to remote repo
git push --remote git@something.url.edu:sys/path/remoterepo.git
# clone the remote repo into a new folder
cd ..
git clone git@something.url.edu:sys/path/remoterepo.git folder2/
mv folder/ folder-old/
mv folder2/ folder/
# Test, everything ok? If so:
rm -rf folder-old/

Check http headers with wget

If you want to see the http headers from your shell, you can do it with:

 

wget --no-check-certificate --server-response --spider https://yourwebsite.something

The result would be something like:

[bash]
Spider mode enabled. Check if remote file exists.
–2014-02-07 11:13:33– https://yourwebsite.something/something
Resolving yourwebsite.something… 129.177.5.226
Connecting to yourwebsite.something|129.177.5.226|:443… connected.
HTTP request sent, awaiting response…
HTTP/1.1 301 Moved Permanently
Date: Fri, 07 Feb 2014 10:13:33 GMT
Server: Apache
Location: https://yourwebsite.something/something/
Vary: Accept-Encoding
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
Location: https://yourwebsite.something/something/ [following]
Spider mode enabled. Check if remote file exists.
–2014-02-07 11:13:33– https://yourwebsite.something/something/
Connecting to yourwebsite.something|129.177.5.226|:443… connected.
HTTP request sent, awaiting response…
HTTP/1.1 301 Moved Permanently
Date: Fri, 07 Feb 2014 10:13:33 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
X-Content-Type-Options: nosniff
Vary: Accept-Encoding,Cookie,User-Agent
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: private, must-revalidate, max-age=0
Last-Modified: Fri, 07 Feb 2014 10:13:33 GMT
Location: http://yourwebsite.something/something/index.php/Hovudside
Connection: keep-alive, Keep-Alive
Keep-Alive: timeout=15, max=100
Content-Type: text/html; charset=utf-8
Location: http://yourwebsite.something/something/index.php/Hovudside [following]
Spider mode enabled. Check if remote file exists.
–2014-02-07 11:13:33– http://yourwebsite.something/something/index.php/Hovudside
Connecting to yourwebsite.something|129.177.5.226|:80… connected.
HTTP request sent, awaiting response…
HTTP/1.1 200 OK
Date: Fri, 07 Feb 2014 10:13:33 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
X-Content-Type-Options: nosniff
Content-language: nn
Vary: Accept-Encoding,Cookie,User-Agent
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: private, must-revalidate, max-age=0
Last-Modified: Tue, 14 Jan 2014 11:52:09 GMT
Connection: keep-alive, Keep-Alive
Keep-Alive: timeout=15, max=100
Content-Type: text/html; charset=UTF-8
Length: unspecified [text language="/html"][/text]
Remote file exists and could contain further links,
but recursion is disabled — not retrieving.
[/bash]