Friday, August 07, 2009

What is SMF and how it works

What is SMF and how it works

Traditionally unix operating systems included set of services, program which listens and respond to request to perform some tasks. For example network,sshd, webserver etc.

Most of unix platforms support rc.d structure to start, stop and to manage it.
But Solaris 10 has implemented new unified feature called Service Management(SMF), still they support rc.d for compatibilty but I think in future they put all services under SMF.

So how SMF is different from traditional rc.d:
SMF is of self healing, it provides automatic recovery from software and hardware failures.
You can get more information about one service, like its dependencies, log locaton etc.
Provides information about misconfiguration so You can identify the reason of failure.

TO manage SMF you can use below commands:

svcs -a -- List of services installed on system
svcs -l -- To get more information
svcadm enable -- To start the service
svcadm disable -- To disable the service
svcs -x -- More information about failure

So when you give command svcs -a, you will realize some weird service names like this

svc:/system/cron:default

This is called Fault Managed Resource identifier(FMRI), it used to identify system objects.

So if you want to stop or restart this service, you can use

svcadm disable svc:/system/cron:default
svcadm refresh svc:/system/cron:default

Thursday, September 11, 2008

Using screen on Linux ...Experience Remote Assistance in CLI

Below are the steps to attach two Linux shell sessions with screen.
Its like Remote Assistance in CLI.

1. Open two terminals with same login.

2. Run ps on both terminals.

3. Run screen -S on 1st terminal.

4. Run cd /var/run/screen/S-; ls on 2nd terminal.

5. Look for 1st terminal's bash PID entry.

6. Run screen -x on 2nd terminal.

Thursday, June 12, 2008

Shell script to monitor ur lab machines

Hello PPL,

After long time I addin new post. Below is the shell script using this can monitor server n their uptime.

[
#!/bin/bash

# add ip / hostname separated by while space
HOSTS="172.30.0.62 172.30.0.41 solaris netra1 172.30.0.76 172.30.0.114 aix"

# no ping request
COUNT=1

# email report when
SUBJECT="Ping failed"
EMAILID1="jack@knowlinux.com"
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "$myHost is not reachable"
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID1 $EMAILID2 $EMAILID3
fi
done
]

Wednesday, December 27, 2006

shell script using expect for cvs automation

Hello PPL,

I always have to check the cvs status using cvs status command, so I tried to automate these things using expect
Expect is a tool for automating interactive
applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really
makes this stuff trivial. Expect is also useful for testing these same
applications. And by adding Tk, you can also wrap interactive applications in
X11 GUIs.
Home page http://expect.nist.gov/

#!/bin/bash

status=$(expect -c "spawn cvs -z9 -d :ext:blog@cvshostname:/path/cvsroot status
expect {password: { send \"password\r\"; exp_continue }
}
exit
")
echo ""
echo "$cvsstatus" > cvsstatus.txt

###continue your shell script after here####

####exit from script#######

Same you can use with ssh, telnet or ftp.
Let me know if some one have better thing with expect package because I am also new with scripting and expect :(

Thanks

Wednesday, October 18, 2006

what is superblock and how to recover it

Hello EB,

The scope of this article not covers about the basic things about file system, but its about troubleshooting of currupt file system.
So, when you create file system on hard drive it will sub devided into multiple file system blocks.
Blocks are used for -
1. To store user data
2. Some blocks used for to store file system's metadata.
(Metadata is kind of structure of your file system and it contents superblock, indoes and directories)

Superblock - Each of your filesystem has a superblock. File system like ext2. ext3 etc. Superblock contents the information about file system like -
* File system type
* Size
* Status
* Information about other metadata

Now you will guess that how important is superblock for your filesystem, if that is that currupt then you may not able to use that partition or may you will error while tring to mount that filesystem.
Following are some errors when superblock get currupts or some bad sectors
- You cant able to mount the filesystem, it will refuse to mount
- Filesystem gets hang
- Sometimes though you are able to mount that filesystem, but strange behavior occures.

These kind of errors occures because of bunch reasons. Most of the time fsck works fine for these errors -
$e2fsck -f /dev/hda3

(-f option for forcefully checking even filesystem seems clean)

Now fsck doesnt work because of lost of superblock, what you will do??
Note that Linux maintains multiple redundant copies of the superblock in every filesystem. You can find out this information with this following command -
$dumpe2fs /dev/hda6 grep -i superblock
dumpe2fs 1.32 (09-Nov-2002)
Primary superblock at 1, Group descriptors at 2-2
Backup superblock at 8193, Group descriptors at 8194-8194
Backup superblock at 24577, Group descriptors at 24578-24578
Backup superblock at 40961, Group descriptors at 40962-40962
Backup superblock at 57345, Group descriptors at 57346-57346
Backup superblock at 73729, Group descriptors at 73730-73730

To repair file system by alternative superblock
$e2fsck -f -b 8193 /dev/hda6

(Take backup using dd before doing running commands)

If you are using Sun Solaris, as My experience frequent power failure can get you hell :-( . I am using old sparc and one time in month I have run fsck using commands as per my last blog. So if your Sun Solaris lost the superblock then boot from cdrom or network, to retrive information about your filesystem's superblock give following command -
$newfs -N /dev/rdsk/devicename

Now use alternative superblock
$fsck -F ufs -o b=block-number /dev/rdsk/devicename

okie guys, hope this information helps somebody.

Tuesday, October 17, 2006

smb partition mounting using mount command

Hello EB,

Here is the useful commands when you want to browse the smb shared files using user name, password and even you can specify specific domain -

smbclient -W domain -L smbhost(IP) -U vishalh
mount -t smbfs -o username=amolk,password,workgroup=domain //smbhost(IP)/share /mnt

Wednesday, October 04, 2006

Sun Solaris - Solution for fsck error at boot time

Hello EB,

Most of time we get some problems with Sun solaris machines at boot time, generally it because of bad sectors or damaged file system. Machine go into File system repair option, so deal with these kind of problems use following commands -

fsck -F (ufs/vxfs) /dev/rdsk/(partition)

noninteractive :fsck tries to repair all the problems it finds in a file system without stopping for user response useful in case of a large number of inconsistencies in a file system but has the disadvantage of removing some useful files which are detected to be corrupt .
If file system is found to have problem at the booting time non interactive fsck fsck is run and all errors which are considered safe to correct are corrected. But if still file system has problems the system boots in single user mode asking for user to manually run the fsck to correct the problems in file system

fsck -F (ufs/vxfs) -Y /dev/rdsk/(partition)

Please use this option at your own risk because it will consider "yes" option for every qwestion so your filesystem might get modified.
Some fsck options as follows -

fsck [ -F fstype] [-V] [-yY] [-o options] special
-F fstype type of file system to be repaired ( ufs , vxfs etc)
-V verify the command line syntax but do not run the command
-y or -Y Run the command in non interactive mode - repair all errors encountered without waiting for user response.
-o options Three options can be specified with -o flag
b=n where n is the number of next super block if primary super block is corrupted in a file system .
p option used to make safe repair options during the booting process.
f force the file system check regardless of its clean flag.
special - Block or character device name of the file system to be checked/repaired - for example /dev/rdsk/c0t3d0s4 .Character device should be used for consistencies check & repair
phases:
fsck checks the file system in a series of 5 pages and checks a specific functionality of file system in each phase.
** phase 1 - Check Blocks and Sizes
** phase 2 - Check Pathnames
** phase 3 - Check Connectivity
** phase 4 - Check Reference Counts
** phase 5 - Check Cylinder Groups