11 February 2008

Split a file into several ones with dd

To split quickly a file in several ones (for greatest management, better legibility ...), the dd command can be used.

To create the /path/to/my/destination/file with the first N MBytes of the /path/to/my/source/file:
dd if=/path/to/my/source/file of=/path/to/my/destination/file bs=1048576 count=N

Manage services under Solaris

A simple refresh of what can be done with svcs and svcadm tools.

Get list of all services:
svcs

Add a service:
To begin, a manifest file is needed to define the service (some information there).
Then, it is needed to ensure it is valid:
xmllint --valid /path/to/my/service/manifest/file

Finally, the service can be add:
svccfg import /path/to/my/service/manifest/file

Activate a service (which has been priorly added):
svcadm enable * serviceName
The -s option can be used to get focus only after the service is fully activated (or failed).

Disable a service:
svcadm disable * serviceName
The -s option can be used to get focus only after the service has been disabled.

Put a service under maintenance:
svcadm mark * serviceName

Remove the "maintenance" status of a service:
svcadm clear * serviceName

Update the configuration of a service:
svcadm refresh * serviceName

Get the current status of a service:
svcs -x serviceName stop

Manage services under GNU/Linux distributions providing service and chkconfig

A simple refresh of what can be done with service and chkconfig tools.

Get list of all services and their state for each runlevel (including inet and/or xinet if available):
chkconfig --list

Get state for each runlevel of one service (including inet and/or xinet if available):
chkconfig --list serviceName

Remove a service:
chkconfig --del serviceName

Add a service (with state for each runlevel defined automatically according to the service definition file):
chkconfig --add serviceName

Add a service with specific state for some runlevels:
chkconfig --level * serviceName on|off**
* one or several runlevel(s) specified without separator
** only "on" as sense there (to add/activate the service)

Define the state for some runlevels of an installed service:
chkconfig --level * serviceName on|off*
* "on" to "activate" the service, "off" otherwise

Get the current status of all services:
service --status-all

Get the current status of a service:
service serviceName status

Start a service:
service serviceName start

Stop a service:
service serviceName stop

Restart a service:
service serviceName restart

Request DEB packages ("Debian-like" GNU/Linux distribution)

A simple refresh of what can be done with dpkg tool.

All those commands query installed packages.

Get the list of packages:
dpkg -l

Get the list of packages matching a specific pattern:
dpkg -l pattern
For instance for libraries: dpkg -l lib*

General information about a package:
dpkg -s myPackageName[-myCompletePackageVersion]

Get the list of files of a package:
dpkg -L myPackageName

Get the package providing a specific file:
dpkg -S myFilePathOrPattern*
*: absolute path or pattern

To get the general information of the package providing a specific file (under GNU/Bash) with only one command line:
dpkg -s $( dpkg -S myFilePath |awk '{print $1}' |sed -e 's/://g;' )

Request RPM packages ("Redhat-like" GNU/Linux distribution)

Request RPM packages ("Redhat-like" GNU/Linux distribution)
A simple refresh of what can be done with rpm tool.

To begin, the -q option allow to select the RPM packages to request.
The -a option allow to select all (potentially with a pattern to match).
Name, pattern and even version can be specified for greatest precision in selection.

All those commands query installed packages.

Get the list of packages:
rpm -qa

Get the list of packages matching a specific pattern:
rpm -qa pattern
For instance for X libraries: rpm -qa lib*X*

General information about a package:
rpm -qi myPackageName[-myCompletePackageVersion]
For instance, for a specific kernel: rpm -qi kernel-2.6.20-1.2962.fc6

Get the list of files of a package:
rpm -ql myPackageName[-myCompletePackageVersion]

Get ChangeLog of a package:
rpm -q --changelog myPackageName[-myCompletePackageVersion]

Get the list of packages needed by another package:
rpm -qR myPackageName[-myCompletePackageVersion]

Get the list of what provides a package:
rpm -q --provides myPackageName[-myCompletePackageVersion]

Get the list of packages providing a specific functionality:
rpm -q --whatprovides functionalityName
For instance, for the perl functionality "Authen::SASL": rpm -q --whatprovides "perl(Authen::SASL)"

Get the package providing a specific file:
rpm -qf myFilePath*
*: the path can be relative to current directory or absolute

To get the general information of the package providing a specific file (under GNU/Bash) with only one command line:
rpm -qi $( rpm -q --file myFilePath )