Monday, April 14, 2014

Change a String in All Files in a Directory 

The script shown in this section does a search and replace in all files in a directory, replacing one
string with another and making a backup of the original files. The for loop that you see in the script causes the sed command to be executed for each file in the current directory. The sed command does the actual search and replace work, and at the same time it writes the new versions of any affected files to a temporary directory.

>cat chg_all.sh
 #!/bin/ksh
 tmpdir=tmp.$$
 mkdir $tmpdir.new
 for f in $*
do
  sed -e 's/oldstring/newstring/g'\
 < $f > $tmpdir.new/$f
done

# Make a backup first!
mkdir $tmpdir.old
mv $* $tmpdir.old/
cd $tmpdir.new
mv $* ../

cd ..
rmdir $tmpdir.new

When executing this script, pass in a file mask as an argument. For example, to change only SQL
files, the command would be executed like this:

root>chg_all.sh *.sql

The command in this example causes the string oldstring to be changed to newstring in all .sql files
in the current working directory. Remember that the strings to be changed are specified in the script, while the file mask is passed as a parameter. I don't pass the old and new strings as parameters
because the sed command can be quite tricky, especially if your strings contain special characters.
The sed command that you see in the script invokes the "string editor" for Unix.

The sed command always makes a copy of the changed files, and it never changes a file in-place. Hence, you see in this example that the sed command writes new versions of all changed files to the $tmpdir.new directory. The changes are actually made using sed before the backup copies are made. However, the new
versions of the files are not copied back from $tmpdir.new until after the old versions have been
copied to the backup directory. 

Samba configuration with quota

1)Samba Configuration :

RPM : samba , samba-common, samba-clientDaemon : smbdPORT : 136,137,138conf file : /etc/samba/smb.conf
#rpm -ivh samba-*.*

step1 :

#vi /etc/samba/smb.conf
copy last lines 265 to 272 and paste at the end of file .
275 [myshare] //show this name from windows . 276 comment = ashik and red 277 path = /shared 278 valid users = ashik red 279 public = no 280 writable = yes 281 printable = no 282 create mask = 0765
:wq
step 2:

#useradd ashik and red
#smbpasswd -a ashik;red
#service smb restart
#testparm /etc/samba/smb.conf //show all files which I have been shared in server.


From Linux Client :
* smbclient //192.168.0.244/shared -U ashik > ls >help
*smbclient -L 192.168.0.244 -U red

From windows :
go to run : //192.168.0.244
or,
ftp://192.168.0.244
or ,
from network neighbour .

2) Quota Configuration :


a)
[root@localhost home]# df -hFilesystem Size Used Avail Use% Mounted on/dev/hda8 9.1G 1.9G 6.8G 22% /tmpfs 1006M 0 1006M 0% /dev/shm/dev/hda9 3.9G 72M 3.6G 2% /home
b) umount /dev/hda9 /home
[root@server ~]# mkfs -t ext3 /dev/hda9mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)393216 inodes, 785169 blocks39258 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=80530636824 block groups32768 blocks per group, 32768 fragments per group16384 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.

b)
cat /etc/fstab[root@localhost home]# cat /etc/fstab LABEL=/1 / ext3 defaults 1 1devpts /dev/pts devpts gid=5,mode=620 0 0tmpfs /dev/shm tmpfs defaults 0 0#LABEL=/home /home ext3 defaults 1 2/dev/hda9 /home ext3 defaults,usrquota 0 0proc /proc proc defaults 0 0sysfs /sys sysfs defaults 0 0LABEL=SWAP-hda10 swap swap defaults 0 0[root@localhost home]#
# mount -a# mount
c)
[root@server ~]# quotacheck -mc /home ; if problem ,restart server
[root@server ~]# quotacheck -mc /home[root@server ~]# quotaon -a [root@server ~]# useradd -d /home/pink pink ; smbpasswd -a pink
4)
[root@server ~]# chmod 777 /quota
[root@server ~]# edquota pinkDisk quotas for user pink (uid 502): Filesystem blocks soft hard inodes soft hard /dev/sdb1 0 5 10 0 0 0
5)
[root@server ~]# edquota -tGrace period before enforcing soft limits for users:Time units may be: days, hours, minutes, or seconds Filesystem Block grace period Inode grace period /dev/sdb1 7days 7days

From user end :


Login as Pink
#cd /quota

#touch file1

Note
The soft limit (soft =) specifies the maximum amount of disk usage a quota user is allowed to have. The hard limit (hard =) specifies the absolute limit on the disk usage a quota user can't go beyond it.



 Submit a Task to Run in the Background

The nohup command can be used to submit a task as a background process. This is useful for long-running Oracle jobs, because it frees up your command prompt so that you can do other work. It is especially useful when you are dialed in to an Oracle server using a modem, and you want to free up your terminal session.

Assume that you have a script named run_sql.ksh that executes SQL*Plus commands. The following nohup command can be used to submit that script for background processing:

>> nohup run_sql.ksh > logfile.lst 2>&1 &


There's obviously more to this command than just nohup, and it's important to understand just what each element of the command is doing. For this example, the elements are as follows:

a)nohup :
Submits the task so that it continues to run even after you disconnect your terminal session.
 
b)run_sql.ksh
Specifies the Unix shell script that you want to run in the background.

c) logfile.lst
Redirects standard output to the specified file.

d)2 > &1
Redirects standard error messages to the standard output device. The 2 represents the
standard error device, and 1 represents the standard output device.

e)&
Runs the task in the background.

You need to have a space in front of the trailing ampersand (&) character, and it's that & that causes the task to run as a background task. The nohup command is frequently used with background tasks, because without it all your background tasks would terminate the moment you logged off of Unix.

The nohup command allows a task to continue running long after you've logged off and gone home for the night .


2) Ensure That Only the Oracle User Can Run a Script 

The following if statement will ensure that a Unix script is executed only by the Unix user named
oracle :
if [ `whoami` != 'oracle' ]
then
   echo "Error: You must be oracle to execute."
   exit 99
fi
This statement offers extra security and protection against unauthorized execution. For example, a
script that shuts down the Oracle database should be executed only by the Oracle user. While Unix
permissions offer execution protection, good Unix programmers will also ensure that the proper user

is running the script. 

Saturday, April 5, 2014

Service Name and Transport Protocol Port Number

Service names and port numbers are used to distinguish between different services that run over transport protocols such as TCP, UDP, DCCP, and SCTP. Port numbers are assigned in various ways, based on three ranges: System Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private Ports (49152-65535) > System Ports are assigned by IETF (Internet Engineering Task Force) > User Ports are assigned by IANA (Internet Assigned Numbers Authority) > Dynamic Ports are not assigned. Assigned ports both System and User ports SHOULD NOT be used without or prior to IANA registration.