Unix hints and stuff
Summary: I work extensively with Unix systems administration. This is a page intended as a quick reference for myself and as a possible help to you. Some tips apply to specific Unix dialects others should work with almost any Unix. In some cases the trick or hint involve a particular third-party software package that isn't necessarily a part of the operating system.
A Short introduction
There are always things that are useful but that you somehow never is able to commit to memory. This page is intended for that kind of stuff. So don't expect organized, or relevant, settle for useful. Not all of it, at least not to all people, but if the circumstances are right maybe crucial information. Personally I intend to use this page as a repository filled with stuff that I perhaps never will have use of again, mixed with things that I'll reference often but just don't care to remember. The only thing you won't find here are lengthy references or How to's. There are other forums for that.
Generic tips
- In Swedish: Ta bort filer i
Unix
En sida om hur man tar bort filer som har fått konstiga namn och inte kan tas bort med vanliga medel. -
List only directories
It useful to be able to list all directories in the current directory without any of the files.$ ls -l | grep "^d"
Alias it by adding this in your .login or .profile or .cshrc files in your home directory:
$ alias dir 'ls -l | grep "^d"'
-
fuser instead of ps for pid
There is another way to look for the PID of a particular process instead of piping the output of the ps command into grep and chopping it up. Solaris 2.x (and maybe some other SVR4s) can use the fuser(1) command. Simply use the following command from a Bourne Shell:fuser /path/to/executable 2>/dev/null
The fuser command prints out the PID of all processes that currently have opened the named file, and all processes have their own executable's text segment open.
The fuser command will also print out the PID of all processes that have a file or files open for reading, or that are using the named directory as the current directory. The PIDs are printed on standard output. Formatting and the name of the file(s) are printed on standard error. It also takes a switch -k to send the KILL signal to all PIDs found.
This is much more reliable than grepping the ps output.
-
Cleanup DOS files
If you deal with DOS files and the ^M character always appears at the end of the line, here is one way to get rid of them.$ sed 's/^V^M//g' foo > foo.new
NOTE: ^V is control V and ^M is control M or Enter
-
Stripping man pages
Stripping the escape characters from a man page so that it can be printed on any printer, or just written out as a plain-text file is easy. Say you wanted to write the man page for vi to a file:$ man - vi | col -b > filename.txt
You could then edit the file or print it without the nasty little escape sequences.
-
Using tar to copy files
To use tar to copy files and directories with permissions and ownership:$ tar cvf - [source] | (cd [destination]; tar xvf - )
i.e. $ tar cvf - logsentry | (cd /usr/local; tar xvf - )
Solaris tips
- le0: No carrier - cable disconnected or hub link test
disabled
This is usually logged in /var/adm/messages and on the console. It's caused by an Ethernet card that isn't connected. If this is intended the messages can be stopped by doing:
# eeprom | grep tpe
tpe-link-test?=true
# eeprom 'tpc-link-test?=false'
-
Telnet and ftp connects are slow or time out
This is usually name server related. If the server that you are connecting to is primarily using it's host file to identify others hosts but still using dns to access the Internet this problem may occur. Look in your /etc/nsswitch.conf file if you have a line that looks like this:hosts: files dns
If another host telnets to this host the connect can be slow or time out if the connecting host isn't present in this hosts /etc/hosts and it's name and address cannot be resolved through dns. This is caused by in.telnetd and in.ftpd trying to resolve the connecting hosts name and ip-address, failing and eventually timing out. The problem often occurs on internal networks (behind a firewall or nat router) where you haven't set up an internal dns server to resolve host names. One possible solution is to remove dns from the line in /etc/nsswitch.conf, but this only makes time outs happen sooner.
Another solution is to make sure that all machines on the internal network share a common /etc/hosts file that is always kept updated with all internal hosts on all internal hosts.
-
patchadd exit codes
When installing patch bundles you get a lot of return codes from the various patches in the bundle. These are patchadd exit codes, and patchadd is a script that is used during the patching procedure. I constantly forget what they mean, this list can be found inside the patchadd script or here:- No error
- Usage error
- Attempt to apply a patch that's already been applied
- Effective UID is not root
- Attempt to save original files failed
- pkgadd failed
- Patch is obsoleted
- Invalid package directory
- Attempting to patch a package that is not installed
- Cannot access /usr/sbin/pkgadd (client problem)
- Package validation errors
- Error adding patch to root template
- Patch script terminated due to signal
- Symbolic link included in patch
- NOT USED
- The prepatch script had a return code other than 0.
- The postpatch script had a return code other than 0.
- Mismatch of the -d option between a previous patch install and the current one.
- Not enough space in the file systems that are targets of the patch.
- $SOFTINFO/INST_RELEASE file not found
- A direct instance patch was required but not found
- The required patches have not been installed on the manager
- A progressive instance patch was required but not found
- A restricted patch is already applied to the package
- An incompatible patch is applied
- A required patch is not applied
- The user specified backout data can't be found
- The relative directory supplied can't be found
- A pkginfo file is corrupt or missing
- Bad patch ID format
- Dryrun failure(s)
- Path given for -C option is invalid
- Must be running Solaris 2.6 or greater
- Bad formatted patch file or patch file not found
- Incorrect patch spool directory
- Later revision already installed
HP/UX tips
-
Configuring Samba on HPUX
If you have downloaded a binary distribution of Samba for HPUX you may see the following messages in your samba log:Failed to set gid privileges to (-1,-2) now set to (0,0) uid=(0,0)
PANIC: failed to set gid
The problem is that the guest account by default is nobody, in the group nogroup. On HPUX, this user and group has a negative uid/gid, which will cause samba to log these messages or (in worst case) to core. To fix this, create a user and group like the following:
/etc/passwd:
smbnull:*:119:101:DO NOT USE OR DELETE - needed by Samba:/home/smbnull:/sbin/noshell
/etc/group:
smbnull::101:
Finally, add the following line to your global section of the smb.conf file.
guest account = smbnull