Tuesday, November 24, 2009

How do I block specific incoming ip address?

following iptable rule will drop incoming connection from host/IP 72.30.2.43:

iptables -A INPUT -s 72.30.2.43 -j DROP
iptables -A OUTPUT -d 72.30.2.43 -j DROP

service iptables status

iptables -D INPUT -s 72.30.2.43 -j DROP
iptables -D OUTPUT -d 72.30.2.43 -j DROP

Monday, November 23, 2009

chmod 777 filename

owner rwx
group rwx
other rwx

chmod 7777 filename

4000 - Set the effective User ID
2000 - Set the effective Group ID
1000 - Set the sticky bit

So a file of 7777 means:
a file which is read-writable-executable by all, and has its setuid, groupuid and sticky bits set.

chmod u+x filename

add execute permission on file to owner

u - owner
g - group
o - others
a - all

chmod ug=rw filename

chmod ug+r filename

chmod o-w filename

Question: I have a file i can't read/write/execute with the user i want!

Bad advice:

  • Bad: "chmod 666 file" - This makes the file editable and destroyable by anyone.
  • Worse: "chmod 777 file" - This makes the file editable by anyone AND sets execute permissions for anyone. Fucking stupid. This means that any user can edit the file to do something malicious for the next user to (accidentally?) execute it.
  • Worst: "chmod 7777 file" - Also gives setuid and setgid permission. With this shining example of stupidity you've just given any user permission to fuck your machine up the ass, especially if the file is owned by root.

Good advice:

Make sure the file is owned by an appropriate user or group, and set permissions for that user or group. Create a new group if necessary.

I haven't yet found one example where 777 are the proper permissions for a file or directory.
("But /tmp and /var/tmp!?" i hear you cry. They have permissions 1777.)

ref: http://kreiger.linuxgods.com/kiki/?Bad+linux+advice

ls -ltr

drwxr-xr-x  2 ariel    staff         512 Jun 13 16:19 Mail

- regular file
d - directory
l - link
c - character special device
b - block special device
p - pipe
s - socket

file permissions
rwx - owner
r-x - group
r-x - other

create pipes in Redhat

cd /tmp

mknod fifo_file p

ls -ltr file_file

------tty 1----------
echo passing this line >> /tmp/fifo_file

------tty 2----------
cat < /tmp/fifo_file

create a new partition in Redhat

fdisk /dev/sda

p - print the partition table

n - create new partition

[Enter] to accept the default starting cyclinder

+20M

w - update the partition table

restart or type partprobe to use the new partition

mkfs.ext3 /dev/sda7

mount /dev/sda7 /mnt

umount /mnt

Friday, November 20, 2009

open crontab -e in vi editor

EDITOR=vi;
export EDITOR

Now, crontab -e will open a vi editor for me. :-)

Runlevels in redhat linux

Generally, Red Hat Linux operates in runlevel 3 — full multi-user mode. The following runlevels are defined in Red Hat Linux:

  • 0 — Halt
  • 1 — Single-user mode
  • 2 — Not used (user-definable)
  • 3 — Full multi-user mode
  • 4 — Not used (user-definable)
  • 5 — Full multi-user mode (with an X-based login screen)
  • 6 — Reboot

How to register an ActiveX control (.ocx) manually

You can use the Microsoft Register Server (Regsvr32.exe) to register a 32- bit .ocx file manually on a 32-bit operating system

Regsvr32 [/u] [/s] 

Note
/u means Unregister the .ocx file.
/s means Silent Mode (display no messages).

Ref http://support.microsoft.com/kb/146219

Tuesday, September 15, 2009

notepad trick #1

If you press F5 in notepad, it will insert current date and time in the file. I think most of us know about this notepad trick. It is also mentioned in the Edit menu of the notepad.

Notepad isn't really that bad. It also has a few tricks. For instance, if you want to insert the time and date, simply hit F5. Or, if you want to "log" the times you edit a particular text file, be sure to type: ".LOG" (without the quotes) as the first line of that file and save it. Now every time you open it up, the current date and time will be automatically stamped into it.

Thursday, July 30, 2009

adding users in Ubuntu

Add a User on Ubuntu Server
Ubuntu Server is like any Linux variety, and has full multi-user capabilities, and a common task on any server is adding users.

useradd

The useradd command will let you add a new user easily from the command line:

useradd <username>

This command adds the user, but without any extra options your user won’t have a password or a home directory.

You can use the -d option to set the home directory for the user.
The -m option will force useradd to create the home directory.
We’ll try creating a user account with those options, and then use the passwd command to set the password for the account.

You can alternatively set a password using -p on the useradd command,
but I prefer to set the password using passwd.

sudo useradd -d /home/testuser -m testuser
sudo passwd testuser

This will create the user named testuser and give them their own home directory in /home/testuser. The files in the new home directory are copied from the /etc/skel folder, which contains default home directory files. If you wanted to set default values for your users, you would do so by modifying or adding files in that directory. If we take a look at the new home directory for the user:

jerome@krymz-laptop:/etc/skel$ ls -la /home/testuser
total 20
drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34 .
drwxr-xr-x 5 root root 4096 2006-12-15 11:37 ..
-rw-r–r– 1 testuser testuser 220 2006-12-15 11:34 .bash_logout
-rw-r–r– 1 testuser testuser 414 2006-12-15 11:34 .bash_profile
-rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc


You’ll notice that there are bash scripts in this directory. If you wanted to set default path options for all new users, you would do so by modifying the files in /etc/skel, which would then be used to create these files by the useradd command.

adduser

The adduser
command is even easier than the useradd command,
because it prompts you for each piece of information.
I find it slightly funny that there are two virtually identically named commands that do the same thing, but that’s linux for you.

Here’s the syntax:

adduser <username>


Example:
jerome@krymz-laptop:/etc/skel$ sudo adduser zionuser:
Adding user `zionuser’…
Adding new group `zionuser’ (1004).
Adding new user `zionuser’ (1004) with group `zionuser’.
Creating home directory `/home/zionuser’.
Copying files from `/etc/skel’

Enter new UNIX password:
Retype new UNIX

password: No password supplied

Enter new UNIX password:
Retype new UNIX password:

passwd: password updated successfully

Changing the user information for zionuser

Enter the new value, or press ENTER for the default

Full Name []: zioner

Room Number []: 0

Work Phone []: 555-1212

Home Phone []: 555-1212

Other []:

Is the information correct? [y/N] y

Saturday, May 16, 2009

Solaris: Shell script to write output to a file

HiI need to run a sql query each day which retrieves data based on a numerical incremental (MAXID) value. I want then to store the max value from last query ran in a file (tempid) and then use this new number each day to retreive only the new data. Attached is a sample of the script being used.

#!/bin/sh

echo "Retrieve id"

FILE="/tmp/tempid"
MAXID=0

if [ ! -f $FILE ]; then
echo "$FILE : deos not exist"
exit 1
elif [ ! -r $FILE ]; then
echo "$FILE : can not read"
exit 2
fi

# read $FILE using the file descriptors
exec 3<&0 #save standard input
exec 0<$FILE
while read line
do

MAXID=$line

done

#
# Query
#

sh -c "sqlplus etc ................ <

spool /tmp/temp.csv

Friday, May 15, 2009

Check Oracle Version

There are several ways where you can query or retrieve the version number of installed Oracle products:

1. If you just want to check the version information of the Oracle database, simply connect and login to the Oracle database with SQL *Plus. Upon login, you will see:

SQL*Plus: Release 9.2.0.6.0 - Production on Tue Oct 18 17:58:57 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production

The first italic number is the version of the SQL*Plus client and the second italic number is the version of Oracle database which you are connected to .



2. Retrieve the version information from v$version table by using SQL*Plus. In this table you can find version information on Oracle, PL/SQL, etc.

To retrieve the version information for Oracle, you execute the following SQL statement:

select * from v$version where banner like ‘Oracle%’;

It should return something like this:

Banner
————————————————————————————–
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production



3. Version information can also be checked from Installed Products from the Oracle Universal Installer. It will tells you what products is installed on the machine and also its version information too.

In Unix, the installer is located at $ORACLE_HOME/bin/runInstaller.
In Windows, access the installer by Start -> All Programs -> Oracle Installed Products -> Universal Installer.

renaming multiple files in Solaris

If those are the only 3 files ending in .log in your directory, you could do this:

for i in `ls *.log`;do
mv $i $i.bak
done

That would do each one individually but loop through the 3 files so you only have to do the one command.

About

Blogger templates