Category: Miscellaneous

Linux ‘Environment Variables’ 0

Linux ‘Environment Variables’

In windows, when we want a program to run anywhere we simple add it to the PATH section of the environment Variables… Well, what about linux?

ln -s /root/myawesomescript.sh /bin/shortname

# nnow we can run with 'shortname'

 

How to find physical location of /dev/sd* drives in linux 0

How to find physical location of /dev/sd* drives in linux

I wrote a lil script to help out with this.. The syntax is as follows:

finddrive.py sda

How this works is by lighting up the corresponding drive on the front panel for about 3 seconds.

#!/bin/sh

cmd="dd if=/dev/$1 of=/dev/null"
seconds=3

echo "Check front panel for indicator light"
$cmd&

cmdpid=$!
sleep $seconds

if [ -d /proc/$cmdpid ]
then
  # echo "terminating program PID:$cmdpid"
  kill $cmdpid
fi

Credits:  Fabio’s Blog

 

How to setup open MySQL Port (3306) on Ubuntu 0

How to setup open MySQL Port (3306) on Ubuntu

Step 1: ensure we have mysql-server installed.

apt-get install mysql-server

Then: vim /etc/mysql/my.cnf

COMMENT OUT (with a '#'): 
"bind-address = 127.0.0.1"

Restart Server with

service mysql restart

——– To test with another linux client, use

mysql -h ip.or.hostname -u root -p

(ERROR 2003 (HY000): Can’t connect to MySQL server on ‘xyz’)

iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT

( ERROR 1130 (HY000): Host ‘69.80.43.240’ is not allowed to connect to this MySQL server)

Fix in phpmyadmin
Privileges Tab > root > add a new root with All hosts '%'

 

Linux rsync backup script 0

Linux rsync backup script

HOW TO USE:

  1. edit following file and set DIR as the directory you wish to backup.
  2. save as backup.sh
  3. make exceutable with ‘chmod +x backup.sh’
  4. Run with ./backup.sh /mnt/mymedia    (where /mnt/mymedia is the location you wish to backup to
#!/bin/sh

# Enter absolute path of directory you wish to backup
# DO NOT FORGET TRIALING SLASH!!
DIR=/root/importantdir/

# ---------------------- DO NOT EDIT BELOW THIS LINE-------------------------- #

if [ $# -lt 1 ]; then
    echo "No destination defined. Usage: $0 destination" >&2
    exit 1
elif [ $# -gt 1 ]; then
    echo "Too many arguments. Usage: $0 destination" >&2
    exit 1
fi

START=$(date +%s)

DAY=`date +%d`
MONTH=`date +%m`
YEAR=`date +%Y`
TIME=$(date '+%A, %d %B %Y, %T')

TODAY="$YEAR""_""$MONTH""_""$DAY"

BKDIR="$1/$TODAY"
LOG=$BKDIR/backup_$TODAY.log

if [ ! -d "$BKDIR" ]; then
        mkdir -p $BKDIR
fi

echo "Backup on: $TIME n" > $LOG
rsync -aAXvh $DIR* $BKDIR | tee -a $LOG

FINISH=$(date +%s)

echo "total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds" >> $LOG

 

How to change date and timezone in linux 0

How to change date and timezone in linux

To change date:

date -s "18 JUN 2013 12:22:00"

To change timezone:

sudo dpkg-reconfigure tzdata

 

NOTE: After changing linux date/time/timezone make sure you restart cron with:

/etc/init.d/cron stop
/etc/init.d/cron start

#or in Ubuntu/Debian based OS's

service cron stop
service cron start

 

Reference: Linux ‘top’ command 0

Reference: Linux ‘top’ command

us: user cpu time (or) % CPU time spent in user space
sy: system cpu time (or) % CPU time spent in kernel space
ni: user nice cpu time (or) % CPU time spent on low priority processes
id: idle cpu time (or) % CPU time spent idle
wa: io wait cpu time (or) % CPU time spent in wait (on disk)
hi: hardware irq (or) % CPU time spent servicing/handling hardware interrupts
si: software irq (or) % CPU time spent servicing/handling software interrupts
st: steal time – – % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine