Linux Admin Blog

System Administration, Linux, Solaris, Backup, Networking, Security, Mysql, Script, Tips & Tricks

Archive for the ‘Tips & Tricks’ Category

Working with tar and tar Encryption

Posted by sanjaydalal4u on July 2, 2009

STEP 1 :  (Using the tar command on the directory /example)

Suppose you have a directory /stuff. To tar everything in stuff to create a “.tar” file.

# tar -cvf example.tar example

It will create example.tar file.

STEP 2 :  (Using the tar command to create a “.tar.gz” of /example)

# tar -czf example.tar.gz example

STEP 3 :  (List the files in the archive)

# tar -tzf example.tar.gz
or
# tar -tf example.tar

STEP 4 :   (ENCRYPTION)

# tar -zcvf – example | openssl des3 -salt -k secretpassword | dd of=example.des3

This will create example.des3…Please don’t forget the password you put in place of secretpassword.

If you want to do this interactively then

# dd if=example.des3 |openssl des3 -d -k secretpassword|tar zxf -

Posted in Linux Commands, Tips & Tricks | Leave a Comment »

Network configuration for Debian

Posted by sanjaydalal4u on July 2, 2009

Ip from dhcp

#/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

For a static IP

#/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 10.8.0.100
netmask 255.255.255.0
gateway 10.8.0.1
broadcast 10.8.0.255

Posted in Networking, Tips & Tricks | Leave a Comment »

Assigning a virtual IP to a NIC

Posted by sanjaydalal4u on July 2, 2009

Assigning a virtual IP to a NIC is a very easy task either you use the system-config-network tool or just do some text file editing. The script ifconfig can also be used to create a virtual network interface, but this would not be permanent since the changes ifconfig makes do not survive a reboot.

In Fedora, all information about the network interfaces is kept in the following directories:

  • /etc/sysconfig/network-scripts/
  • /etc/sysconfig/networking/

My NIC configuration script is /etc/sysconfig/network-scripts/ifcfg-eth0 looks like this:

DEVICE=eth0

BOOTPROTO=static

BROADCAST=192.168.0.255

HWADDR=00:00:00:00:00:00

IPADDR=192.168.0.1

NETMASK=255.255.255.0

NETWORK=192.168.0.0

ONBOOT=yes

TYPE=Ethernet

GATEWAY=192.168.0.254

Make a copy of this in the same directory naming the new file ifcfg-eth0:1

# cp ifcfg-eth0 ifcfg-eth0\:1

Modification in file ifcfg-eth0\:1 is shown in bold

DEVICE=eth0:1

BOOTPROTO=static

BROADCAST=192.168.0.255

HWADDR=00:00:00:00:00:00

IPADDR=192.168.0.101

NETMASK=255.255.255.0

NETWORK=192.168.0.0

ONBOOT=yes

TYPE=Ethernet

GATEWAY=192.168.0.254

So, its IP address will be 192.168.0.101. Save the file and copy it to/etc/sysconfig/networking/devices/:

# cp ifcfg-eth0\:1 /etc/sysconfig/networking/devices/

Also, copy it to your default network profile or whichever profile you use:

# cp ifcfg-eth0\:1 /etc/sysconfig/networking/profiles/default/

Now, bring up the new interface using the ifup script:

# ifup eth0\:1

Running ifconfig, the new interface should be listed. You can also check it by pinging:

# ping 192.168.0.101

Posted in Networking, Tips & Tricks | Leave a Comment »

Vncserver configuration file to start GNOME

Posted by sanjaydalal4u on May 27, 2009

The configuration is kept in the file /home/userxx/.vnc/xstartup I edited this file so that I can start the server with gnome. My file looks exactly like below.

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

gnome-session &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
# xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
twm &

Posted in Tips & Tricks, vncserver | Leave a Comment »

Installing Gnome Desktop on CentOs/RHEL/Fedora/Ubuntu Server installation

Posted by sanjaydalal4u on May 12, 2009

# yum groupinstall “X Window System”  “GNOME Desktop Environment”

This should install GNOME Desktop on your System…

For Ubuntu server

#aptitute install ubuntu-desktop or

#apt-get install ubuntu-desktop


Enjoy…….

Posted in Tips & Tricks | Leave a Comment »

Import data to mysql database from .txt files using “Sed”

Posted by sanjaydalal4u on May 8, 2009

Review the post :http://sanjaybdalal.wordpress.com/2009/05/08/export-mysql-tables-in-txt-files/  . In this post we have export the mysql database data into the .txt files. 

Now we are import the data from .txt files to mysql database. For that we have to reformate the .txt files data which will support in the sql format.

#cat example.txt

1,SANJAY,AHMEDABAD,SYSTEM ADMIN

1,PRIYA,PUNE,PERL DEVELOPER

1,AKSHAY,GONDAL,PERL DEVELOPER

1,MIHIR,MUMBAI,PERL DEVELOPER

Now using “sed” command we will format this file to support sql.

 

sed -e ’s/,/”,”/g’ -e ’s/^/insert into example values(“/g’ -e ’s/$/”);/g’ example.txt

#sed -e ’s/,/”,”/g’ -e ’s/^/insert into example values(“/g’ -e ’s/$/”);/g’ example.txt > example.txt.new

where ^ represent start to the line and $ represent end of the line.

Output :

#cat example.txt.new

 insert into example values(“1″,”SANJAY”,”AHMEDABAD”,”SYSTEM ADMIN”);

insert into example values(“1″,”PRIYA”,”PUNE”,”PERL DEVELOPER”);

insert into example values(“1″,”AKSHAY”,”GONDAL”,”PERL DEVELOPER”);

insert into example values(“1″,”MIHIR”,”MUMBAI”,”PERL DEVELOPER”);

Posted in HowTo, Mysql, Sed, Tips & Tricks | Leave a Comment »

Export mysql tables in .txt files

Posted by sanjaydalal4u on May 8, 2009

mysql> use test;

mysql> SELECT *FROM example;

+——+——–+———–+—————-+

| ID   | NAME   | ADDRESS   | REMARKS        |

+——+——–+———–+—————-+

|    1 | SANJAY | AHMEDABAD | SYSTEM ADMIN   |

|    1 | PRIYA  | PUNE      | PERL DEVELOPER |

|    1 | AKSHAY | GONDAL    | PERL DEVELOPER |

|    1 | MIHIR  | MUMBAI    | PERL DEVELOPER |

+——+——–+———–+—————-+

4 rows in set (0.00 sec)

#mysqldump -u root -p –fields-terminated-by=, –tab=/location –table test example 

Above command will create the file example.txt which contains the export data in /location directory

Output: example.txt

#cat /location/example.txt

1,SANJAY,AHMEDABAD,SYSTEM ADMIN

1,PRIYA,PUNE,PERL DEVELOPER

1,AKSHAY,GONDAL,PERL DEVELOPER

1,MIHIR,MUMBAI,PERL DEVELOPER

Posted in HowTo, Mysql, Tips & Tricks | 1 Comment »

Read File using Shell Script

Posted by sanjaydalal4u on May 7, 2009

#!/bin/bash
FILENAME=”filename.txt”
exec 0< $FILENAME
while read LINE
do
echo $LINE
done

 

#!/bin/bash

FILENAME=”filename.txt”

exec 0< $FILENAME

while read LINE

do

     echo $LINE

done

Posted in HowTo, Scripts, Tips & Tricks | Leave a Comment »

Remove Blank lines from file

Posted by sanjaydalal4u on May 7, 2009

 

sed ‘/./!d’ backupfilelist.txt > temp1.txt
sed ‘/^$/d’ backupfilelist.txt > temp1.txt
grep -v ‘^   

filename.txt > temp1.txt

Tech 1 :   sed ‘/./!d’ filename.txt > temp1.txt

Tech 2 :  sed ‘/^$/d’ filename.txt > temp1.txt

Tech 3 :  grep -v ‘^$’ filename.txt > temp1.txt

Posted in HowTo, Linux Commands, Tips & Tricks | Leave a Comment »

Find Command Tips

Posted by sanjaydalal4u on May 5, 2009

Find out multiple files                                                                                                                

Find out multiple extention files with Total size
find / \( -name ‘*.mpg’ -o -name ‘*.mp3′ -o -name ‘*.mov’ -o -name ‘*.wma’ \) -exec du -sk {} \; | awk ‘{c+=$1} END {printf “%s KB\n”, c}’

#find / \( -name ‘*.mpg’ -o -name ‘*.mp3′ -o -name ‘*.mov’ -o -name ‘*.wma’ \) -exec du -sk {} \; 

 

Find out multiple extention files with Total size

find / \( -name ‘*.mpg’ -o -name ‘*.mp3′ -o -name ‘*.mov’ -o -name ‘*.wma’ \) -exec du -sk {} \; | awk ‘{c+=$1} END {printf “%s KB\n”, c}’

Posted in Tips & Tricks | Leave a Comment »