linux

mkdir /where/you/wantem
cd /source/dir
find * -type d -exec mkdir /where/you/wantem/\{\} \;

Modern Linux system uses UUID instead of traditional block name (/dev/hda1, /dev/hda5, /dev/sdb) to uniquely identify harddisk or other storage medium. This is because UUID is unique and never changes even if you switch the harddisk ordering.

So by mounting or refering your hard disk by its UUID, you are guaranteed to mount the correct storage medium no matter where its connected on your system.

Here’s how to get your harddisk UUID number:

Method 1: Ubuntu and Debian Way

sudo vol_id /dev/hda1

This command display harddisk extra information including its filesystem and uuid number.

Method 2: using /dev/disk/by-uuid/

Another method which works universally on modern GNU Linux operating system is :

ls -l /dev/disk/by-uuid

which will uuid of connected storage medium to your computer.

That’s all, now you can easily identify your storage disk UUID number without much problem anymore.

if else bash:

S=”5″

if [[ “${S}” -le “4” && “${S}” -ge “2” ]]; then
echo “in range ”
else
echo “out of range”

FTP automation

ftp -n < file.txt
structure of “file.txt”:

open ftp.server.com
user username
password password
bin
lcd local/dir
cd remote/dir
put temp.txt
bye

Bash “function” example

#!/bin/bash
function dupa {
du -m --max-depth=0 -c ${dir}
}
dir=/var
dupa
dir=/etc
dupa

Ubuntu midnight commander fuckin annoying bug solution:

mc_4.7.0.1-1~karmic1~ppa1_amd64.deb

mc_4.7.0.1-1~karmic1~ppa1_i386.deb

mc_4.7.0.1-1~karmic1~ppa1_lpia.deb

Checking Directory

DIR_PATH=`readlink -f "${the_stuff_you_test}"` # get rid of symlinks and get abs path
if [[ -d "${DIR_PATH}" ]] ; then # now you're testing
echo "It's a dir";
fi

Finding directory

found=`find -type d -name "myDirectory"`
if [ -n "$found"]
then
# found is not empty
fi

Reset mysql root password.

Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.

mysqld_safe --skip-grant-tables

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

mysql --user=root mysql

update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;

Now kill your running mysqld, then restart it normally. You should be good to go. Try not to forget your password again.

Running script from cron every 80 sec.

*/4 * * * * /scripts/80_second_script
*/4 * * * * sleep 80; /scripts/80_second_script
*/4 * * * * sleep 160; /scripts/80_second_script

Line 1 runs at 0,240,480,etc…
Line 2 runs at 80,320,560, etc…
Line 3 runs at 160,400,640, etc…

Put that all together you get
0,80,160,240,320,400,480,560,640, etc…

You can do this with any number, but the more often the multiples of your number cross the multiples of 60 the less lines you have to write.

Copying files using tar and ssh

ssh user@machine-where-precious-data-is "tar czpf - /some/important/data" | tar xzpf - -C /new/root/directory

tar cXpf - /some/important/data | ssh user@destination-machine "tar xpf - -C /some/directory/"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s